aboutsummaryrefslogtreecommitdiffstats
path: root/library/python/pytest
diff options
context:
space:
mode:
authorqrort <qrort@yandex-team.com>2022-11-17 19:38:20 +0300
committerqrort <qrort@yandex-team.com>2022-11-17 19:38:20 +0300
commit487326d832ec22895f2c9209df5407c17f2c816d (patch)
tree8cedd0ccc03d0ae4d251ef98934277af92181dd0 /library/python/pytest
parent019071feb92f224930b5975d31ecc110f467a618 (diff)
downloadydb-487326d832ec22895f2c9209df5407c17f2c816d.tar.gz
yatest_common context file test
Diffstat (limited to 'library/python/pytest')
-rw-r--r--library/python/pytest/plugins/conftests.py8
-rw-r--r--library/python/pytest/plugins/fixtures.py7
-rw-r--r--library/python/pytest/plugins/metrics.py10
-rw-r--r--library/python/pytest/plugins/ya.py10
4 files changed, 24 insertions, 11 deletions
diff --git a/library/python/pytest/plugins/conftests.py b/library/python/pytest/plugins/conftests.py
index 2ea36ae4c2..37062bda06 100644
--- a/library/python/pytest/plugins/conftests.py
+++ b/library/python/pytest/plugins/conftests.py
@@ -8,7 +8,7 @@ import yatest.common as yc
from pytest import hookimpl
from yatest_lib.ya import Ya
-from .fixtures import metrics, links # noqa
+from library.python.pytest.plugins.fixtures import metrics, links # noqa
orig_getfile = inspect.getfile
@@ -27,7 +27,11 @@ conftest_modules = []
@hookimpl(trylast=True)
def pytest_load_initial_conftests(early_config, parser, args):
yc.runtime._set_ya_config(ya=Ya())
- conftests = filter(lambda name: name.endswith(".conftest"), sys.extra_modules)
+
+ if hasattr(sys, 'extra_modules'):
+ conftests = filter(lambda name: name.endswith(".conftest"), sys.extra_modules)
+ else:
+ conftests = []
def conftest_key(name):
if not name.startswith("__tests__."):
diff --git a/library/python/pytest/plugins/fixtures.py b/library/python/pytest/plugins/fixtures.py
index 6f7e0a27e4..98e91ce41a 100644
--- a/library/python/pytest/plugins/fixtures.py
+++ b/library/python/pytest/plugins/fixtures.py
@@ -2,6 +2,7 @@ import os
import pytest
import six
+from library.python.pytest.plugins.metrics import test_metrics
MAX_ALLOWED_LINKS_COUNT = 10
@@ -15,9 +16,9 @@ def metrics(request):
assert len(name) <= 128, "Length of the metric name must less than 128"
assert type(value) in [int, float], "Metric value must be of type int or float"
test_name = request.node.nodeid
- if test_name not in request.config.test_metrics:
- request.config.test_metrics[test_name] = {}
- request.config.test_metrics[test_name][name] = value
+ if test_name not in test_metrics.metrics:
+ test_metrics[test_name] = {}
+ test_metrics[test_name][name] = value
@classmethod
def set_benchmark(cls, benchmark_values):
diff --git a/library/python/pytest/plugins/metrics.py b/library/python/pytest/plugins/metrics.py
new file mode 100644
index 0000000000..b6431c8b8e
--- /dev/null
+++ b/library/python/pytest/plugins/metrics.py
@@ -0,0 +1,10 @@
+class TestMetrics:
+ metrics = {}
+ def __getitem__(self, key):
+ return self.metrics.__getitem__(key)
+ def __setitem__(self, key, value):
+ return self.metrics.__setitem__(key, value)
+ def get(self, key):
+ return self.metrics.get(key)
+
+test_metrics = TestMetrics()
diff --git a/library/python/pytest/plugins/ya.py b/library/python/pytest/plugins/ya.py
index b641b26c0c..5d8bfb25b9 100644
--- a/library/python/pytest/plugins/ya.py
+++ b/library/python/pytest/plugins/ya.py
@@ -32,6 +32,8 @@ from _pytest.warning_types import PytestUnhandledCoroutineWarning
from yatest_lib import test_splitter
import yatest.common as yatest_common
+from library.python.pytest.plugins.metrics import test_metrics
+
try:
import resource
except ImportError:
@@ -66,7 +68,6 @@ SHUTDOWN_REQUESTED = False
pytest_config = None
-
def configure_pdb_on_demand():
import signal
@@ -184,7 +185,6 @@ def pytest_addoption(parser):
def from_ya_test():
return "YA_TEST_RUNNER" in os.environ
-
@pytest.hookimpl(tryfirst=True)
def pytest_configure(config):
global pytest_config
@@ -194,7 +194,7 @@ def pytest_configure(config):
config.from_ya_test = from_ya_test()
config.test_logs = collections.defaultdict(dict)
- config.test_metrics = {}
+ test_metrics.metrics = {}
config.suite_metrics = {}
config.configure_timestamp = time.time()
context = {
@@ -283,7 +283,6 @@ def pytest_configure(config):
configure_pdb_on_demand()
yatest_common.runtime._set_ya_config(config=config)
-
# Dump python backtrace in case of any errors
faulthandler.enable()
if hasattr(signal, "SIGQUIT"):
@@ -293,7 +292,6 @@ def pytest_configure(config):
if hasattr(signal, "SIGUSR2"):
signal.signal(signal.SIGUSR2, _graceful_shutdown)
-
session_should_exit = False
@@ -850,7 +848,7 @@ class TraceReportGenerator(object):
'status': test_item.status,
'comment': comment,
'result': result,
- 'metrics': pytest_config.test_metrics.get(test_item.nodeid),
+ 'metrics': test_metrics.get(test_item.nodeid),
'is_diff_test': 'diff_test' in test_item.keywords,
'tags': _get_item_tags(test_item),
}