1ea05a232SMike Bayer#!/usr/bin/env python
2ea05a232SMike Bayer"""
3ea05a232SMike Bayerpytest plugin script.
4ea05a232SMike Bayer
5405fc971SGord ThompsonThis script is an extension to pytest which
6ea05a232SMike Bayerinstalls SQLAlchemy's testing plugin into the local environment.
7ea05a232SMike Bayer
8ea05a232SMike Bayer"""
9d7498cf4SMike Bayerimport os
101e278de4SMike Bayerimport sys
111e278de4SMike Bayer
1248d22c04SMike Bayerimport pytest
1348d22c04SMike Bayer
145fb0138aSMike Bayer
15ba5cbf93SMike Bayeros.environ["SQLALCHEMY_WARN_20"] = "true"
16ba5cbf93SMike Bayer
175fb0138aSMike Bayercollect_ignore_glob = []
18788ba204SMike Bayer
19788ba204SMike Bayer# minimum version for a py3k only test is at
20788ba204SMike Bayer# 3.6 because these are asyncio tests anyway
21788ba204SMike Bayerif sys.version_info[0:2] < (3, 6):
225fb0138aSMike Bayer    collect_ignore_glob.append("*_py3k.py")
235fb0138aSMike Bayer
2448d22c04SMike Bayerpytest.register_assert_rewrite("sqlalchemy.testing.assertions")
2548d22c04SMike Bayer
26ea05a232SMike Bayer
27f30e35baSMike Bayerif not sys.flags.no_user_site:
2849dfeda6SMike Bayer    # this is needed so that test scenarios like "python setup.py test"
29405fc971SGord Thompson    # work correctly, as well as plain "pytest".  These commands assume
3049dfeda6SMike Bayer    # that the package in question is locally present, but since we have
3149dfeda6SMike Bayer    # ./lib/, we need to punch that in.
3249dfeda6SMike Bayer    # We check no_user_site to honor the use of this flag.
33f30e35baSMike Bayer    sys.path.insert(
34f30e35baSMike Bayer        0,
351e1a38e7SMike Bayer        os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "lib"),
36f30e35baSMike Bayer    )
37d7498cf4SMike Bayer
38d7498cf4SMike Bayer# use bootstrapping so that test plugins are loaded
39d7498cf4SMike Bayer# without touching the main library before coverage starts
40d7498cf4SMike Bayerbootstrap_file = os.path.join(
411e1a38e7SMike Bayer    os.path.dirname(__file__),
421e1a38e7SMike Bayer    "..",
431e1a38e7SMike Bayer    "lib",
441e1a38e7SMike Bayer    "sqlalchemy",
451e1a38e7SMike Bayer    "testing",
461e1a38e7SMike Bayer    "plugin",
471e1a38e7SMike Bayer    "bootstrap.py",
48d7498cf4SMike Bayer)
49d7498cf4SMike Bayer
50d7498cf4SMike Bayerwith open(bootstrap_file) as f:
511e1a38e7SMike Bayer    code = compile(f.read(), "bootstrap.py", "exec")
52d7498cf4SMike Bayer    to_bootstrap = "pytest"
53d7498cf4SMike Bayer    exec(code, globals(), locals())
54d7498cf4SMike Bayer    from pytestplugin import *  # noqa