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
This commit is contained in:
Alexander V. Chernikov
2023-04-01 19:40:54 +00:00
parent fc2538cb7b
commit d9af4219d6
3 changed files with 22 additions and 14 deletions
+15 -6
View File
@@ -6,15 +6,12 @@
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 @@ def _convert_user_mark(mark, obj, ret: Dict):
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 @@ def has_object_cleanup(self, obj):
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()
+5
View File
@@ -11,6 +11,11 @@
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")