Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test failure on Py3.11 #211

Open
sanjayankur31 opened this issue Jul 1, 2022 · 4 comments
Open

Test failure on Py3.11 #211

sanjayankur31 opened this issue Jul 1, 2022 · 4 comments

Comments

@sanjayankur31
Copy link
Contributor

A test is failing on Py3.11 here:

======================================================================
FAIL: test_source_check (sciunit.unit_test.model_tests.CapabilitiesTestCase.test_source_check)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/asinha/Documents/02_Code/01_others/sciunit/sciunit/unit_test/model_tests.py", line 241, in test_source_check
    self.assertFalse(MyCap1.source_check(MyModel2()))
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: True is not false

----------------------------------------------------------------------
Ran 83 tests in 11.860s

FAILED (failures=1, skipped=2)

Steps to reproduce:

  • clone repo
  • install py3.11 and associated developer libraries/headers
  • set up py3.11 virtualenv
  • pip install wheel pytest
  • pip install .
  • chmod +x test.sh
  • ./test.sh
@sanjayankur31
Copy link
Contributor Author

Just double-checked: all tests pass on py3.10:

Ran 83 tests in 9.938s

OK (skipped=2)

@rgerkin
Copy link
Contributor

rgerkin commented Aug 1, 2023

Do you know why this fails in 3.11?

@sanjayankur31
Copy link
Contributor Author

Not sure yet, didn't see anything obvious in the py3.11 release notes that may explain it, so will require a little bit of digging.

@ChihweiLHBird
Copy link
Contributor

ChihweiLHBird commented Aug 6, 2023

The reason was the behavior of Python dis module from the standard library has been changed in Python 3.11.

before 3.11 3.11
image image

Which causes our source check failed

stdout = sys.stdout
sys.stdout = io.StringIO()

dis.dis(getattr(cls, method))

dis_output = sys.stdout.getvalue()
sys.stdout = stdout

dis_output = re.split("\n|\s+", dis_output)
dis_output = [word for word in dis_output if word]

if (
    "(NotImplementedError)" in dis_output
    or "(unimplemented)" in dis_output
    or "(CapabilityNotImplementedError)" in dis_output
    or "(NotImplemented)" in dis_output
):
    cap_source = inspect.getsource(getattr(cls, method))
    model_source = inspect.getsource(getattr(model, method))

    if cap_source == model_source:
        source_capable = False
        break

Because it is now (NULL + NotImplementedError) instead of (NotImplementedError), we can make an ambitious change to check whether NotImplementedError is the substring of the output, but this might cause trouble if there is some other disassembled normal code that includes these strings. This is not very likely, though. Another solution in my mind is to overhaul the Capability system to utilize Python Abstract Base Class to enforce the abstract methods’ implementation, but this is a relatively large change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants