diff --git a/pytest_attrib/plugin.py b/pytest_attrib/plugin.py index 9664f98..89958f5 100644 --- a/pytest_attrib/plugin.py +++ b/pytest_attrib/plugin.py @@ -5,7 +5,7 @@ def pytest_addoption(parser): group = parser.getgroup("general") - group._addoption("-a", action="store", default="", + group._addoption("--eval-attr", "-a", action="store", default="", dest="attrexpr", metavar="ATTREXPR", help='Only run tests matching given attribute expression.' ' Example: -a "attr1==val1 and attr2==val2".') diff --git a/tests/test_attrib.py b/tests/test_attrib.py index d59ff94..7369710 100644 --- a/tests/test_attrib.py +++ b/tests/test_attrib.py @@ -22,6 +22,9 @@ def test_arg(testdir): result = testdir.runpytest("--help") result.stdout.fnmatch_lines("*-a ATTREXPR*") + result = testdir.runpytest("--help") + result.stdout.fnmatch_lines("*--eval-attr=ATTREXPR*") + def test_config(testdir): config = testdir.parseconfig() @@ -38,6 +41,21 @@ def test_config(testdir): assert config.getoption('attrexpr') == 'attr1==val1 and attr2==True' +def test_long_config(testdir): + config = testdir.parseconfig() + assert config.getoption('attrexpr') == '' + + config = testdir.parseconfig('--eval-attr', 'attr1') + assert config.getoption('attrexpr') == 'attr1' + + config = testdir.parseconfig('--eval-attr', 'attr1==val1 and attr2==True') + assert config.getoption('attrexpr') == 'attr1==val1 and attr2==True' + + config = testdir.parseconfig('--eval-attr', 'attr1==val1 and attr2==True', + '-k', 'somethingelse') + assert config.getoption('attrexpr') == 'attr1==val1 and attr2==True' + + @pytest.mark.parametrize("spec", [ ("xyz", ("test_one",)), ("xyz and xyz2", ()),