You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
1.6KB

  1. """
  2. Bootstrapper for test framework plugins.
  3. The entire rationale for this system is to get the modules in plugin/
  4. imported without importing all of the supporting library, so that we can
  5. set up things for testing before coverage starts.
  6. The rationale for all of plugin/ being *in* the supporting library in the
  7. first place is so that the testing and plugin suite is available to other
  8. libraries, mainly external SQLAlchemy and Alembic dialects, to make use
  9. of the same test environment and standard suites available to
  10. SQLAlchemy/Alembic themselves without the need to ship/install a separate
  11. package outside of SQLAlchemy.
  12. NOTE: copied/adapted from SQLAlchemy master for backwards compatibility;
  13. this should be removable when Alembic targets SQLAlchemy 1.0.0.
  14. """
  15. import os
  16. import sys
  17. bootstrap_file = locals()["bootstrap_file"]
  18. to_bootstrap = locals()["to_bootstrap"]
  19. def load_file_as_module(name):
  20. path = os.path.join(os.path.dirname(bootstrap_file), "%s.py" % name)
  21. if sys.version_info >= (3, 3):
  22. from importlib import machinery
  23. mod = machinery.SourceFileLoader(name, path).load_module()
  24. else:
  25. import imp
  26. mod = imp.load_source(name, path)
  27. return mod
  28. if to_bootstrap == "pytest":
  29. sys.modules["sqla_plugin_base"] = load_file_as_module("plugin_base")
  30. sys.modules["sqla_plugin_base"].bootstrapped_as_sqlalchemy = True
  31. if sys.version_info < (3, 0):
  32. sys.modules["sqla_reinvent_fixtures"] = load_file_as_module(
  33. "reinvent_fixtures_py2k"
  34. )
  35. sys.modules["sqla_pytestplugin"] = load_file_as_module("pytestplugin")
  36. else:
  37. raise Exception("unknown bootstrap: %s" % to_bootstrap) # noqa