conftest.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #!/usr/bin/env python
  2. """
  3. pytest plugin script.
  4. This script is an extension to pytest which
  5. installs SQLAlchemy's testing plugin into the local environment.
  6. """
  7. import os
  8. import sys
  9. if not sys.flags.no_user_site:
  10. # this is needed so that test scenarios like "python setup.py test"
  11. # work correctly, as well as plain "pytest". These commands assume
  12. # that the package in question is locally present, but since we have
  13. # ./lib/, we need to punch that in.
  14. # We check no_user_site to honor the use of this flag.
  15. sys.path.insert(
  16. 0,
  17. os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "lib"),
  18. )
  19. # use bootstrapping so that test plugins are loaded
  20. # without touching the main library before coverage starts
  21. bootstrap_file = os.path.join(
  22. os.path.dirname(__file__),
  23. "..",
  24. "lib",
  25. "sqlalchemy",
  26. "testing",
  27. "plugin",
  28. "bootstrap.py",
  29. )
  30. with open(bootstrap_file) as f:
  31. code = compile(f.read(), "bootstrap.py", "exec")
  32. to_bootstrap = "pytest"
  33. exec(code, globals(), locals())
  34. from pytestplugin import * # noqa