aboutsummaryrefslogtreecommitdiffstats
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
parent019071feb92f224930b5975d31ecc110f467a618 (diff)
downloadydb-487326d832ec22895f2c9209df5407c17f2c816d.tar.gz
yatest_common context file test
-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
-rw-r--r--library/python/testing/yatest_common_standalone/README.md5
-rw-r--r--library/python/testing/yatest_common_standalone/__init__.py4
-rw-r--r--library/python/testing/yatest_lib/ya.py18
-rw-r--r--ydb/tests/functional/open_source/resource.txt1
-rwxr-xr-xydb/tests/functional/open_source/script.sh6
-rw-r--r--ydb/tests/functional/open_source/test_yatest_common.py18
10 files changed, 64 insertions, 23 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),
}
diff --git a/library/python/testing/yatest_common_standalone/README.md b/library/python/testing/yatest_common_standalone/README.md
new file mode 100644
index 0000000000..ce177dabb3
--- /dev/null
+++ b/library/python/testing/yatest_common_standalone/README.md
@@ -0,0 +1,5 @@
+## Не используйте эту библиотеку
+
+Её единственное назначение - временно отключить runtime проверки в тестовой машинерии, которая попадает по зависимостям в изолированную программу.
+
+Библиотека будет удалена в ближайшем будущем.
diff --git a/library/python/testing/yatest_common_standalone/__init__.py b/library/python/testing/yatest_common_standalone/__init__.py
new file mode 100644
index 0000000000..795c161a20
--- /dev/null
+++ b/library/python/testing/yatest_common_standalone/__init__.py
@@ -0,0 +1,4 @@
+def init():
+ import yatest.common.runtime
+
+ yatest.common.runtime._relaxed_runtime_allowed = True
diff --git a/library/python/testing/yatest_lib/ya.py b/library/python/testing/yatest_lib/ya.py
index 27ea2e89b2..44a3fd51ca 100644
--- a/library/python/testing/yatest_lib/ya.py
+++ b/library/python/testing/yatest_lib/ya.py
@@ -6,7 +6,6 @@ import json
from .tools import to_str
from .external import ExternalDataInfo
-
TESTING_OUT_DIR_NAME = "testing_out_stuff" # XXX import from test.const
yatest_logger = logging.getLogger("ya.test")
@@ -227,22 +226,17 @@ class Ya(object):
assert self._test_item_node_id
return self._test_item_node_id
- @property
- def pytest_config(self):
- if not hasattr(self, "_pytest_config"):
- import library.python.pytest.plugins.ya as ya_plugin
- self._pytest_config = ya_plugin.pytest_config
- return self._pytest_config
-
def set_metric_value(self, name, val):
+ from library.python.pytest.plugins.metrics import test_metrics
node_id = self.get_test_item_node_id()
- if node_id not in self.pytest_config.test_metrics:
- self.pytest_config.test_metrics[node_id] = {}
+ if node_id not in test_metrics.metrics:
+ test_metrics[node_id] = {}
- self.pytest_config.test_metrics[node_id][name] = val
+ test_metrics[node_id][name] = val
def get_metric_value(self, name, default=None):
- res = self.pytest_config.test_metrics.get(self.get_test_item_node_id(), {}).get(name)
+ from library.python.pytest.plugins.metrics import test_metrics
+ res = test_metrics.get(self.get_test_item_node_id(), {}).get(name)
if res is None:
return default
return res
diff --git a/ydb/tests/functional/open_source/resource.txt b/ydb/tests/functional/open_source/resource.txt
new file mode 100644
index 0000000000..d95f3ad14d
--- /dev/null
+++ b/ydb/tests/functional/open_source/resource.txt
@@ -0,0 +1 @@
+content
diff --git a/ydb/tests/functional/open_source/script.sh b/ydb/tests/functional/open_source/script.sh
new file mode 100755
index 0000000000..c77cca20a4
--- /dev/null
+++ b/ydb/tests/functional/open_source/script.sh
@@ -0,0 +1,6 @@
+#!/bin/sh
+
+ya make -t --test-prepare
+export PYTHONPATH=${PYTHONPATH}:${HOME}/arcadia/library/python/testing:${HOME}/arcadia/library/python/pytest/plugins:${HOME}/arcadia/library/python/testing/yatest_common:${HOME}/arcadia
+export YA_TEST_CONTEXT_FILE=`readlink test-results/py3test/test.context`
+PYTEST_PLUGINS=ya,conftests pytest test_yatest_common.py
diff --git a/ydb/tests/functional/open_source/test_yatest_common.py b/ydb/tests/functional/open_source/test_yatest_common.py
new file mode 100644
index 0000000000..984a5b1ad0
--- /dev/null
+++ b/ydb/tests/functional/open_source/test_yatest_common.py
@@ -0,0 +1,18 @@
+# -*- coding: utf-8 -*-
+import os
+import json
+import yatest.common as ya_common
+
+
+class TestYaTestContext(object):
+ def test_source_path(self):
+ resource_path = 'ydb/tests/functional/open_source/resource.txt'
+ ya_source_path = ya_common.source_path(resource_path)
+ context_file = os.getenv('YA_TEST_CONTEXT_FILE')
+
+ if context_file:
+ with open(context_file, 'r') as content:
+ context_source_path = os.path.join(json.load(content)['runtime']['source_root'], resource_path)
+ assert ya_source_path == context_source_path
+
+ assert os.path.exists(ya_source_path)