diff options
author | nkozlovskiy <[email protected]> | 2023-08-10 15:30:42 +0300 |
---|---|---|
committer | nkozlovskiy <[email protected]> | 2023-08-10 16:36:31 +0300 |
commit | d3a7c7cab345b64d8022b1b8c7a346b579025b2b (patch) | |
tree | 4e2a6bb23e056bf50ea22e077afca97fa90ba457 | |
parent | 30b2fa6cf3b87ff946407b94f4f45a069638af32 (diff) |
add ydb/tests/oss/ci/ci.py as additionalPathToCopy
-rw-r--r-- | ydb/tests/oss/ci/ci.py | 131 | ||||
-rw-r--r-- | ydb/tests/oss/ci/ya.make | 7 | ||||
-rw-r--r-- | ydb/tests/oss/ya.make | 1 |
3 files changed, 139 insertions, 0 deletions
diff --git a/ydb/tests/oss/ci/ci.py b/ydb/tests/oss/ci/ci.py new file mode 100644 index 00000000000..97eb9e265c7 --- /dev/null +++ b/ydb/tests/oss/ci/ci.py @@ -0,0 +1,131 @@ +import contextlib +import os + +import pytest + + +def pytest_sessionstart(session): + def noop(*args, **kwargs): + pass + + assert session.config.pluginmanager + session.config.pluginmanager._check_non_top_pytest_plugins = noop + + +# noinspection PyProtectedMember +def patch_project_path(item): + from ya import pytest_config + + ctx = pytest_config.ya._context + + old_path = ctx["project_path"] + + project_path = os.path.relpath( + os.path.dirname(item.fspath), + pytest_config.ya._source_root, + ) + + ctx["project_path"] = project_path + + try: + yield + finally: + ctx["project_path"] = old_path + + [email protected](hookwrapper=True) +def pytest_make_collect_report(collector): + with patch_project_path(collector): + yield + + +def make_github_link(repo, ref, filepath, lineno): + result = [f"https://github.com/{repo}/blob/{ref}/{filepath}"] + + if lineno: + result.append(f"#L{lineno + 1}") + + return "".join(result) + + +# noinspection PyProtectedMember [email protected](tryfirst=True) +def pytest_runtest_setup(item): + from ya import pytest_config + import library.python.pytest.yatest_tools as tools + + if "PYTEST_XDIST_WORKER" in os.environ: + out_path = os.path.join(pytest_config.option.output_dir, os.environ["PYTEST_XDIST_WORKER"]) + else: + out_path = pytest_config.option.output_dir + + rel_filepath = os.path.relpath(item.path, pytest_config.ya._source_root) + + test_dir = tools.normalize_filename(rel_filepath) + + out_path = os.path.join(out_path, test_dir) + + if not os.path.exists(out_path): + os.makedirs(out_path) + + pytest_config.ya._output_dir = out_path + + junit_props = { + "filename": rel_filepath, + } + + if pytest_config.option.github_repo and pytest_config.option.github_ref: + lineno = item.reportinfo()[1] + junit_props["url:testcase"] = make_github_link( + pytest_config.option.github_repo, + pytest_config.option.github_ref, + rel_filepath, + lineno, + ) + else: + junit_props["testcase"] = item.nodeid + + for k, v in junit_props.items(): + item.user_properties.append((k, v)) + + +# @pytest.hookimpl(tryfirst=True) +# def pytest_runtest_teardown(item, nextitem): +# import tarfile +# from ya import pytest_config +# import library.python.pytest.yatest_tools as tools +# +# artifacts_dir = pytest_config.option.artifacts_dir +# artifacts_url = pytest_config.option.artifacts_url +# +# if not artifacts_dir: +# return +# +# if not os.path.exists(artifacts_dir): +# os.makedirs(artifacts_dir) +# +# class_name, test_name = tools.split_node_id(item.nodeid) +# basename = f"{tools.normalize_filename(class_name)}_{tools.normalize_filename(test_name)}" +# fn = f"{basename}.tar.gz" +# +# tar_fn = os.path.join(artifacts_dir, fn) +# +# with tarfile.open(tar_fn, "w:gz") as tar: +# tar.add(pytest_config.ya._output_dir, basename) +# +# if artifacts_url: +# item.user_properties.append(("url:artifacts", f"{artifacts_url}{fn}")) + + [email protected](hookwrapper=True) +def pytest_runtest_call(item): + with patch_project_path(item): + yield + + +def pytest_addoption(parser): + # parser.addoption("--artifacts-dir", help="path to store test artifacts") + # parser.addoption("--artifacts-url", help="url prefix for artifacts") + parser.addoption("--github-repo", help="junit: link files to specific github repo") + parser.addoption("--github-ref", help="junit: link files to specific changeset") diff --git a/ydb/tests/oss/ci/ya.make b/ydb/tests/oss/ci/ya.make new file mode 100644 index 00000000000..96791e204ae --- /dev/null +++ b/ydb/tests/oss/ci/ya.make @@ -0,0 +1,7 @@ +PY3_LIBRARY() + +PY_SRCS( + ci.py +) + +END() diff --git a/ydb/tests/oss/ya.make b/ydb/tests/oss/ya.make index f9bf3f8458a..4b7d4ee1114 100644 --- a/ydb/tests/oss/ya.make +++ b/ydb/tests/oss/ya.make @@ -1,5 +1,6 @@ RECURSE( canonical + ci launch ydb_sdk_import ) |