aboutsummaryrefslogtreecommitdiffstats
path: root/library/python/pytest/plugins/conftests.py
diff options
context:
space:
mode:
authorDevtools Arcadia <arcadia-devtools@yandex-team.ru>2022-02-07 18:08:42 +0300
committerDevtools Arcadia <arcadia-devtools@mous.vla.yp-c.yandex.net>2022-02-07 18:08:42 +0300
commit1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch)
treee26c9fed0de5d9873cce7e00bc214573dc2195b7 /library/python/pytest/plugins/conftests.py
downloadydb-1110808a9d39d4b808aef724c861a2e1a38d2a69.tar.gz
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'library/python/pytest/plugins/conftests.py')
-rw-r--r--library/python/pytest/plugins/conftests.py50
1 files changed, 50 insertions, 0 deletions
diff --git a/library/python/pytest/plugins/conftests.py b/library/python/pytest/plugins/conftests.py
new file mode 100644
index 0000000000..522041f5a7
--- /dev/null
+++ b/library/python/pytest/plugins/conftests.py
@@ -0,0 +1,50 @@
+import os
+import importlib
+import sys
+import inspect
+
+from pytest import hookimpl
+
+from .fixtures import metrics, links # noqa
+
+orig_getfile = inspect.getfile
+
+
+def getfile(object):
+ res = orig_getfile(object)
+ if inspect.ismodule(object):
+ if not res and getattr(object, '__orig_file__'):
+ res = object.__orig_file__
+ return res
+
+inspect.getfile = getfile
+conftest_modules = []
+
+
+@hookimpl(trylast=True)
+def pytest_load_initial_conftests(early_config, parser, args):
+ conftests = filter(lambda name: name.endswith(".conftest"), sys.extra_modules)
+
+ def conftest_key(name):
+ if not name.startswith("__tests__."):
+ # Make __tests__ come last
+ return "_." + name
+ return name
+
+ for name in sorted(conftests, key=conftest_key):
+ mod = importlib.import_module(name)
+ if os.getenv("CONFTEST_LOAD_POLICY") != "LOCAL":
+ mod.__orig_file__ = mod.__file__
+ mod.__file__ = ""
+ conftest_modules.append(mod)
+ early_config.pluginmanager.consider_conftest(mod)
+
+
+def getconftestmodules(*args, **kwargs):
+ return conftest_modules
+
+
+def pytest_sessionstart(session):
+ # Override filesystem based relevant conftest discovery on the call path
+ assert session.config.pluginmanager
+ session.config.pluginmanager._getconftestmodules = getconftestmodules