aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAlexander V. Chernikov <melifaro@FreeBSD.org>2022-06-28 10:49:41 +0000
committerAlexander V. Chernikov <melifaro@FreeBSD.org>2022-06-28 12:20:16 +0000
commit513ce835b55831d343185e03a51efa2901405ac8 (patch)
tree602f02bacfcb413ce351943ebf4e845281e3b008 /tests
parent8e1c23341c0c1b161f7fe9aa76ca2e399ada9f45 (diff)
downloadsrc-513ce835b55831d343185e03a51efa2901405ac8.tar.gz
src-513ce835b55831d343185e03a51efa2901405ac8.zip
testing: pass ATF vars to pytest via env instead of arguments.
This change is a continuation of 9c42645a1e4d workaround. Apparently pytest argument parser is not happy when parsing values with spaces or just more than one --atf-var argument. Switch wrapper to send these kv pairs as env variables. Specifically, use _ATF_VAR_key=value format to distinguish from the other vars. Add the `atf_vars` fixture returning all passed kv pairs as a dict. Reviewed by: lwhsu Differential Revision: https://reviews.freebsd.org/D35625 MFC after: 2 weeks
Diffstat (limited to 'tests')
-rw-r--r--tests/atf_python/atf_pytest.py6
-rw-r--r--tests/conftest.py7
2 files changed, 12 insertions, 1 deletions
diff --git a/tests/atf_python/atf_pytest.py b/tests/atf_python/atf_pytest.py
index 89c0e3a515b9..f72122fb740e 100644
--- a/tests/atf_python/atf_pytest.py
+++ b/tests/atf_python/atf_pytest.py
@@ -6,6 +6,7 @@ from typing import NamedTuple
from typing import Tuple
import pytest
+import os
class ATFCleanupItem(pytest.Item):
@@ -216,3 +217,8 @@ class ATFHandler(object):
line = "{}: {}".format(test.state, test.reason)
with open(path, mode="w") as f:
print(line, file=f)
+
+ @staticmethod
+ def get_atf_vars() -> Dict[str, str]:
+ px = "_ATF_VAR_"
+ return {k[len(px):]: v for k, v in os.environ.items() if k.startswith(px)}
diff --git a/tests/conftest.py b/tests/conftest.py
index 193d2adfb5e0..65c8bf5f0d01 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -1,5 +1,6 @@
import pytest
from atf_python.atf_pytest import ATFHandler
+from typing import Dict
PLUGIN_ENABLED = False
@@ -17,7 +18,6 @@ def pytest_addoption(parser):
"""Add file output"""
# Add meta-values
group = parser.getgroup("general", "Running and selection options")
- group.addoption("--atf-var", dest="atf_vars", action="append", default=[])
group.addoption(
"--atf-source-dir",
type=str,
@@ -46,6 +46,11 @@ def pytest_addoption(parser):
)
+@pytest.fixture(autouse=True, scope="session")
+def atf_vars() -> Dict[str, str]:
+ return ATFHandler.get_atf_vars()
+
+
@pytest.mark.trylast
def pytest_configure(config):
if config.option.help: