Skip to content

Commit

Permalink
Add the config arg --eval-attr
Browse files Browse the repository at this point in the history
Nose users will get confused by using the -a argument which
uses eval-like syntax while in nose-attrib that arg uses
a different approach. Hence, we add a --eval-attr argument
which allows users to be compatible with both.

Fixes #7
  • Loading branch information
AbdealiLoKo committed May 27, 2016
1 parent c38ae60 commit e2e517c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pytest_attrib/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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".')
Expand Down
18 changes: 18 additions & 0 deletions tests/test_attrib.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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", ()),
Expand Down

0 comments on commit e2e517c

Please sign in to comment.