1#!/usr/bin/env python
2"""
3pytest plugin script.
4
5This script is an extension to pytest which
6installs SQLAlchemy's testing plugin into the local environment.
7
8"""
9import os
10import sys
11
12import pytest
13
14
15os.environ["SQLALCHEMY_WARN_20"] = "true"
16
17collect_ignore_glob = []
18
19# minimum version for a py3k only test is at
20# 3.6 because these are asyncio tests anyway
21if sys.version_info[0:2] < (3, 6):
22    collect_ignore_glob.append("*_py3k.py")
23
24pytest.register_assert_rewrite("sqlalchemy.testing.assertions")
25
26
27if not sys.flags.no_user_site:
28    # this is needed so that test scenarios like "python setup.py test"
29    # work correctly, as well as plain "pytest".  These commands assume
30    # that the package in question is locally present, but since we have
31    # ./lib/, we need to punch that in.
32    # We check no_user_site to honor the use of this flag.
33    sys.path.insert(
34        0,
35        os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "lib"),
36    )
37
38# use bootstrapping so that test plugins are loaded
39# without touching the main library before coverage starts
40bootstrap_file = os.path.join(
41    os.path.dirname(__file__),
42    "..",
43    "lib",
44    "sqlalchemy",
45    "testing",
46    "plugin",
47    "bootstrap.py",
48)
49
50with open(bootstrap_file) as f:
51    code = compile(f.read(), "bootstrap.py", "exec")
52    to_bootstrap = "pytest"
53    exec(code, globals(), locals())
54    from pytestplugin import *  # noqa
55