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 due to confused nox dependencies? #9353

Closed
woodruffw opened this issue Aug 4, 2023 · 2 comments
Closed

Test failure due to confused nox dependencies? #9353

woodruffw opened this issue Aug 4, 2023 · 2 comments

Comments

@woodruffw
Copy link
Contributor

woodruffw commented Aug 4, 2023

From local development: I'm seeing a failure in test_no_circular_imports that doesn't make a lot of sense:

======================================== FAILURES =========================================
________________________________ test_no_circular_imports _________________________________
[gw0] darwin -- Python 3.11.2 /Users/william/devel/cryptography/.nox/tests/bin/python      
                                                                                           
subtests = <tests.conftest.SubTests object at 0x114b336d0>                                 
                                                                                           
    def test_no_circular_imports(subtests):                                                
        env = os.environ.copy()                                                            
        env["PYTHONPATH"] = os.pathsep.join(sys.path)                                      
                                                                                           
        # When using pytest-cov it attempts to instrument subprocesses. This               
        # causes the memleak tests to raise exceptions.                                    
        # we don't need coverage so we remove the env vars.                                
        env.pop("COV_CORE_CONFIG", None)                                                   
        env.pop("COV_CORE_DATAFILE", None)                                                 
        env.pop("COV_CORE_SOURCE", None)                                                   
                                                                                           
        for module in find_all_modules():                                                  
            with subtests.test():                                                          
                argv = [sys.executable, "-c", f"__import__({module!r})"]                   
>               subprocess.check_call(argv, env=env)                                       
                                                                                           
tests/test_meta.py:38:                                                                     
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
                                                                                           

With traceback:

  File "<string>", line 1, in <module>                                                     
  File "/Users/william/devel/cryptography/.nox/tests/lib/python3.11/site-packages/cryptogra
phy/hazmat/backends/openssl/ec.py", line 14, in <module>                                   
    from cryptography.hazmat.backends.openssl.utils import (                               
ImportError: cannot import name '_evp_pkey_derive' from 'cryptography.hazmat.backends.opens
sl.utils' (/Users/william/devel/cryptography/.nox/tests/lib/python3.11/site-packages/crypto
graphy/hazmat/backends/openssl/utils.py)                                                   

Observe that this appears to happen in ec.py, which was removed with #9024. The path also suggests that this copy of cryptography is coming from nox's own dependencies, and the two (nox's and the local environment's) are getting confused in the test suite somehow.

Remediations attempted

I attempted to blow away my local venv, as well as the nox-created venvs at .nox. Neither changed the behavior here.

Reproduction steps

I'm not sure if others will be able to reproduce this, but on macOS with CPython 3.11:

python -m venv env && source env/bin/activate
python -m pip install -e .[nox,test]
nox -e tests

Edit: a more minimal reproducer, without nested envs:

pipx install nox
nox -e tests
@woodruffw
Copy link
Contributor Author

woodruffw commented Aug 4, 2023

SWAG is that this:

import cryptography


def find_all_modules() -> typing.List[str]:
    return sorted(
        mod
        for _, mod, _ in pkgutil.walk_packages(
            cryptography.__path__,
            prefix=cryptography.__name__ + ".",
        )
    )

...is actually importing and walking through the nox-specified cryptography somehow, and not the local one under test.

@woodruffw
Copy link
Contributor Author

Figured it out: nox was copying files from build/, which I hadn't blown away and still contained files that were deleted in the actual source tree.

rm -r build did the trick.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 3, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

1 participant