From nobody Sat Apr 1 19:44:54 2023 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4PpngC1jsNz43FwB; Sat, 1 Apr 2023 19:44:55 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4PpngC1CF5z4Llq; Sat, 1 Apr 2023 19:44:55 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1680378295; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=7BIVHOiwSF4fuvZgj/FHRJkrrbRil3rGXywQsArHScQ=; b=co4QAHVG7gg6f8GYpfuUQIyMJyKiHSzNUHTqNfhzHpO1oShbw6AMQ66MkE2+y0/nv+07F7 YtBeZp8NxXz3urzQyUpBDvuC7bM55tIHMOCftqm/YvZpE3JPRXdBkWgmOhsOAbcGB5GKzT vgrzsI1unD/J/elPBrvuetk4CXviqGErTY7wc7pcTQUUAQCFXQCSG+q7YPvng2UbT24fDS 2Y07unvY0ho2IGeepiMpFGf8mSe62MT2Tjir3NLkdXw+HWTuZbwn9yLWSM/rOZrv1zMfJB owaAX+xdiK2S0TuEJKD2SoipTNg+S9Hmt3ww/NIg+LedyEswaKKoZonJD/NgRQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1680378295; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=7BIVHOiwSF4fuvZgj/FHRJkrrbRil3rGXywQsArHScQ=; b=ooUpSuItdanJIi7wUvXXcaHTd4RTNalN8KJrodDkra0Qo+SomSzmUqkZsUhobEq0yHOzt1 BLVDwC2w/Tx1bIAyxpNi1DSbp1kXbubZ1/cBrFD0BXH9GM25fMzCeLuqyRwGNFRgNLo4D6 YMePmZM4cs6BLsmvkYQ2pOq5unoT8ZSo7FDbJG/KUbWAmbpYr2p8Cj1hb0MeDCrTPz89pe q+N89d3F11grK20ecBdNFk0Rkeyk6M9AiMXp/KEHrEbpqNHgNxe1lx83FhYhSioZohZ/8y vQNJwgR1I/Hh0i9h8KhxamI19dYCDp25S6Ql49iZ3KQCBtZMc9tgV5F8JZVAMQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1680378295; a=rsa-sha256; cv=none; b=gH2f4TZ3Ho8NUvUxHnnjhLRyzlUlHRdcEvb+HhR1mYfTgWk2+k40KgZuw5b5P6tDjOixOf mtUHREKZSWUzh0dN3QMD9Uo+wiOEJoAjqaSbQVYfUwP/SXhxXUpWZrgKyUPrisUWiWggrh h+yHvGAXgy74rcAmbKqkg/XcI7o3CvIQvqQBebcDDKQr4+FIfhc2JzjKfg8j26Dp+6RX5T J+Sp6OzhnVFmUUDGZex9Uj7H7ntG7OfF1xOUXb3FSNhLUBzOLARzep46OfNphl+p22ikId 6cRlyJRAsmbI5BFVVmna4iHTZD50jOchtFIKLvCy5WD99ikYdHb3jFMIZmonZQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4PpngC0Gs1zp7l; Sat, 1 Apr 2023 19:44:55 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 331JisCi029381; Sat, 1 Apr 2023 19:44:54 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 331Jis1P029380; Sat, 1 Apr 2023 19:44:54 GMT (envelope-from git) Date: Sat, 1 Apr 2023 19:44:54 GMT Message-Id: <202304011944.331Jis1P029380@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: "Alexander V. Chernikov" Subject: git: d9af4219d668 - main - tests: refactor atf_python a bit List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: melifaro X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: d9af4219d668f4f16574f757d6fc4c7971a4ef2c Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by melifaro: URL: https://cgit.FreeBSD.org/src/commit/?id=d9af4219d668f4f16574f757d6fc4c7971a4ef2c commit d9af4219d668f4f16574f757d6fc4c7971a4ef2c Author: Alexander V. Chernikov AuthorDate: 2023-04-01 19:40:54 +0000 Commit: Alexander V. Chernikov CommitDate: 2023-04-01 19:44:37 +0000 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 --- tests/atf_python/atf_pytest.py | 21 +++++++++++++++------ tests/atf_python/utils.py | 5 +++++ tests/conftest.py | 10 ++-------- 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):