test_meta.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. # This file is dual licensed under the terms of the Apache License, Version
  2. # 2.0, and the BSD License. See the LICENSE file in the root of this repository
  3. # for complete details.
  4. import os
  5. import pkgutil
  6. import subprocess
  7. import sys
  8. import typing
  9. import cryptography
  10. def find_all_modules() -> typing.List[str]:
  11. return sorted(
  12. mod
  13. for _, mod, _ in pkgutil.walk_packages(
  14. cryptography.__path__,
  15. prefix=cryptography.__name__ + ".",
  16. )
  17. )
  18. def test_no_circular_imports(subtests):
  19. env = os.environ.copy()
  20. env["PYTHONPATH"] = os.pathsep.join(sys.path)
  21. # When using pytest-cov it attempts to instrument subprocesses. This
  22. # causes the memleak tests to raise exceptions.
  23. # we don't need coverage so we remove the env vars.
  24. env.pop("COV_CORE_CONFIG", None)
  25. env.pop("COV_CORE_DATAFILE", None)
  26. env.pop("COV_CORE_SOURCE", None)
  27. for module in find_all_modules():
  28. with subtests.test():
  29. argv = [sys.executable, "-c", f"__import__({module!r})"]
  30. subprocess.check_call(argv, env=env)