Skip to content

Commit

Permalink
Merge pull request #1217 from jremmet/pytest_stash
Browse files Browse the repository at this point in the history
pytest.stash instead of protected member
  • Loading branch information
Emantor committed Jun 30, 2023
2 parents 80595d5 + 13486c7 commit 7e418f2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
3 changes: 2 additions & 1 deletion labgrid/pytestplugin/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from ..resource.remote import RemotePlace
from ..util.ssh import sshmanager
from ..logging import DEFAULT_FORMAT
from .hooks import LABGRID_ENV_KEY

# pylint: disable=redefined-outer-name

Expand Down Expand Up @@ -60,7 +61,7 @@ def env(request, record_testsuite_property):
"""Return the environment configured in the supplied configuration file.
It contains the targets contained in the configuration file.
"""
env = request.config._labgrid_env
env = request.config.stash[LABGRID_ENV_KEY]

if not env:
pytest.skip("missing environment config (use --lg-env)")
Expand Down
7 changes: 5 additions & 2 deletions labgrid/pytestplugin/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
from ..util.helper import processwrapper
from ..logging import StepFormatter, StepLogger

LABGRID_ENV_KEY = pytest.StashKey[Environment]()


@pytest.hookimpl(tryfirst=True)
def pytest_cmdline_main(config):
def set_cli_log_level(level):
Expand Down Expand Up @@ -89,15 +92,15 @@ def pytest_configure(config):
env = Environment(config_file=lg_env)
if lg_coordinator is not None:
env.config.set_option('crossbar_url', lg_coordinator)
config._labgrid_env = env
config.stash[LABGRID_ENV_KEY] = env

processwrapper.enable_logging()

@pytest.hookimpl()
def pytest_collection_modifyitems(config, items):
"""This function matches function feature flags with those found in the
environment and disables the item if no match is found"""
env = config._labgrid_env
env = config.stash[LABGRID_ENV_KEY]

if not env:
return
Expand Down

0 comments on commit 7e418f2

Please sign in to comment.