Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Release 0.5.0 (unreleased)
New Features in 0.5.0
~~~~~~~~~~~~~~~~~~~~~
- Support for Eaton ePDU added, and can be used as a NetworkPowerPort.
- Consider a combination of multiple "lg_feature" markers instead of
considering only the closest marker.

Bug fixes in 0.5.0
~~~~~~~~~~~~~~~~~~
Expand Down
20 changes: 9 additions & 11 deletions labgrid/pytestplugin/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ def pytest_configure(config):
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"""
have_feature = []
env = config._labgrid_env

if not env:
Expand All @@ -62,17 +61,16 @@ def pytest_collection_modifyitems(config, items):
have_feature = env.get_features() | env.get_target_features()

for item in items:
marker = item.get_closest_marker("lg_feature")
if not marker:
continue
want_feature = set()

arg = marker.args[0]
if isinstance(arg, str):
want_feature = set([arg])
elif isinstance(arg, list):
want_feature = set(arg)
else:
raise Exception("Unsupported feature argument type")
for marker in item.iter_markers("lg_feature"):
arg = marker.args[0]
if isinstance(arg, str):
want_feature.add(arg)
elif isinstance(arg, list):
want_feature.update(arg)
else:
raise Exception("Unsupported feature argument type")
missing_feature = want_feature - have_feature
if missing_feature:
if len(missing_feature) == 1:
Expand Down
67 changes: 67 additions & 0 deletions tests/test_flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,70 @@ def test(env):
spawn.expect(pexpect.EOF)
spawn.close()
assert spawn.exitstatus == 0

def test_match_multi_feature_source(tmpdir):
conf = tmpdir.join("config.yaml")
conf.write(
"""
targets:
test1:
features:
- test1
- test2
- test3
drivers: {}
"""
)
test = tmpdir.join("test.py")
test.write(
"""
import pytest

pytestmark = pytest.mark.lg_feature("test1")

@pytest.mark.lg_feature("test2")
class TestMulti:
@pytest.mark.lg_feature("test3")
def test(self, env):
assert True
"""
)

with pexpect.spawn(f'pytest --lg-env {conf} {test}') as spawn:
spawn.expect("1 passed")
spawn.expect(pexpect.EOF)
spawn.close()
assert spawn.exitstatus == 0

def test_skip_multi_feature_source(tmpdir):
conf = tmpdir.join("config.yaml")
conf.write(
"""
targets:
test1:
features:
- test1
- test3
drivers: {}
"""
)
test = tmpdir.join("test.py")
test.write(
"""
import pytest

pytestmark = pytest.mark.lg_feature("test1")

@pytest.mark.lg_feature("test2")
class TestMulti:
@pytest.mark.lg_feature("test3")
def test(self, env):
assert True
"""
)

with pexpect.spawn(f'pytest --lg-env {conf} {test}') as spawn:
spawn.expect("1 skipped")
spawn.expect(pexpect.EOF)
spawn.close()
assert spawn.exitstatus == 0