aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander V. Chernikov <melifaro@FreeBSD.org>2023-04-01 19:40:54 +0000
committerAlexander V. Chernikov <melifaro@FreeBSD.org>2023-04-01 19:44:37 +0000
commitd9af4219d668f4f16574f757d6fc4c7971a4ef2c (patch)
tree91574d6662888471484847d4fe1041bb8b559f23
parentfc2538cb7bdb8e22afc331c3733f2e306624be9e (diff)
downloadsrc-d9af4219d668f4f16574f757d6fc4c7971a4ef2c.tar.gz
src-d9af4219d668f4f16574f757d6fc4c7971a4ef2c.zip
tests: refactor atf_python a bit
* Move more logic from conftest.py to the actual atf_pytest handler * Move nodeid_to_method_name() to the utils.py so it can be shared MFC after: 2 weeks
-rw-r--r--tests/atf_python/atf_pytest.py21
-rw-r--r--tests/atf_python/utils.py5
-rw-r--r--tests/conftest.py10
3 files changed, 22 insertions, 14 deletions
diff --git a/tests/atf_python/atf_pytest.py b/tests/atf_python/atf_pytest.py
index db7244d3234b..0dd3a225b73d 100644
--- a/tests/atf_python/atf_pytest.py
+++ b/tests/atf_python/atf_pytest.py
@@ -6,15 +6,12 @@ from typing import NamedTuple
from typing import Optional
from typing import Tuple
+from atf_python.utils import nodeid_to_method_name
+
import pytest
import os
-def nodeid_to_method_name(nodeid: str) -> str:
- """file_name.py::ClassName::method_name[parametrize] -> method_name"""
- return nodeid.split("::")[-1].split("[")[0]
-
-
class ATFCleanupItem(pytest.Item):
def runtest(self):
"""Runs cleanup procedure for the test instead of the test itself"""
@@ -73,7 +70,6 @@ class ATFTestObj(object):
else:
ret["require.user"] = username
-
def _convert_marks(self, obj) -> Dict[str, Any]:
wj_func = lambda x: " ".join(x) # noqa: E731
_map: Dict[str, Dict] = {
@@ -158,6 +154,19 @@ class ATFHandler(object):
return True
return False
+ def _generate_test_cleanups(self, items):
+ new_items = []
+ for obj in items:
+ if self.has_object_cleanup(obj):
+ self.override_runtest(obj)
+ new_items.append(obj)
+ items.clear()
+ items.extend(new_items)
+
+ def modify_tests(self, items, config):
+ if config.option.atf_cleanup:
+ self._generate_test_cleanups(items)
+
def list_tests(self, tests: List[str]):
print('Content-Type: application/X-atf-tp; version="1"')
print()
diff --git a/tests/atf_python/utils.py b/tests/atf_python/utils.py
index c8146b943ce9..591a532ca476 100644
--- a/tests/atf_python/utils.py
+++ b/tests/atf_python/utils.py
@@ -11,6 +11,11 @@ from typing import Optional
import pytest
+def nodeid_to_method_name(nodeid: str) -> str:
+ """file_name.py::ClassName::method_name[parametrize] -> method_name"""
+ return nodeid.split("::")[-1].split("[")[0]
+
+
class LibCWrapper(object):
def __init__(self):
path: Optional[str] = find_library("c")
diff --git a/tests/conftest.py b/tests/conftest.py
index 687f6bde375e..5d319863af73 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -101,15 +101,9 @@ def pytest_configure(config):
def pytest_collection_modifyitems(session, config, items):
"""If cleanup is requested, replace collected tests with their cleanups (if any)"""
- if PLUGIN_ENABLED and config.option.atf_cleanup:
- new_items = []
+ if PLUGIN_ENABLED:
handler = get_handler()
- for obj in items:
- if handler.has_object_cleanup(obj):
- handler.override_runtest(obj)
- new_items.append(obj)
- items.clear()
- items.extend(new_items)
+ handler.modify_tests(items, config)
def pytest_collection_finish(session):