Verified Commit 8cc886cb authored by Karel Koci's avatar Karel Koci 🤘
Browse files

tests: move target specification to top level

This allows to run selftests not on all available targets but only on
specified one. This way we do not pollute the results with test of any
other target.

This also improves marks initialization. Marks with limited effect
(those are lan1 and lan2) are defined in runtime. This makes their
definition and effect at the same level and thus we should be able to
better manage them.
parent db1b9aab
......@@ -9,6 +9,11 @@ def pytest_addoption(parser):
help="Path to configuration file with additional targets.",
"-T", "--target",
help="Run tests on specified TARGET.",
......@@ -20,6 +25,8 @@ def pytest_configure(config):
# Parse target cgnfiguration
targets ="-C") or (), rootdir=config.rootdir)
setattr(config, "targets", targets)
# Set selected target (None if there is no such target)
setattr(config, "target_config", targets.get(config.getoption("-T")))
class HTMLReport:
......@@ -7,5 +7,3 @@ markers =
deploy: quick tests to be run as part of deployment process
board(boards): mark test to run only on specified boards
not_board(boards): mark test to not run on specified boards
lan1: requirement of lan1 ethernet connection to board
lan2: requirement of lan2 ethernet connection to board
......@@ -8,14 +8,10 @@ import nsfarm.board
import nsfarm.cli
import nsfarm.lxd
from . import mark
def pytest_addoption(parser):
"-T", "--target",
help="Run tests on specified TARGET.",
help="Run tests on one of the targets with given BOARD unless exact target is specified.",
......@@ -30,15 +26,16 @@ def pytest_addoption(parser):
def pytest_configure(config):
# Set target configuration
target_name = config.getoption("-T")
if target_name is None:
# Select target configuration unless explicitly specified from top level conftest
if config.target_config is None:
target_name = next(config.targets.filter(board=config.getoption("--board")))
# If there was no target selection then we chose one
# Note: We can run tests only on one target. This way we force selftests to run on our target only.
setattr(config, "target_config", config.targets[next(
except StopIteration:
if target_name is not None: # Targets might not be set for example with --help argument
setattr(config, "target_config", config.targets[target_name])
# Set target branch
branch = config.getoption("-B")
setattr(config, "target_branch", branch)
......@@ -46,7 +43,7 @@ def pytest_configure(config):
# Store configuration to metadata (basically just for pytest-html)
if hasattr(config, '_metadata'):
'NSFarm-Target': target_name,
'NSFarm-TurrisBranch': branch,
......@@ -3,6 +3,11 @@ name.
import pytest
"lan1: requirement of lan1 ethernet connection to board",
"lan2: requirement of lan2 ethernet connection to board",
# Exclusive for boards
only_turris1x = pytest.mark.board("turris1x")
only_omnia = pytest.mark.board("omnia")
......@@ -20,3 +25,10 @@ rainbow = pytest.mark.board("omnia", "turrix1x")
low_ram = pytest.mark.board("mox")
atsha = pytest.mark.board("omnia", "turrix1x")
otp = pytest.mark.board("mox")
def register_marks(config):
"""Registers all tests specific markers.
for mark in MARKERS:
config.addinivalue_line("markers", mark)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment