refactor mark tests, widen catching and make error msg more concise
This commit is contained in:
parent
87edc09dea
commit
251e8f212e
|
@ -84,13 +84,8 @@ def matchmark(colitem, markexpr):
|
||||||
"""Tries to match on any marker names, attached to the given colitem."""
|
"""Tries to match on any marker names, attached to the given colitem."""
|
||||||
try:
|
try:
|
||||||
return eval(markexpr, {}, MarkMapping.from_item(colitem))
|
return eval(markexpr, {}, MarkMapping.from_item(colitem))
|
||||||
except (SyntaxError, TypeError):
|
except Exception:
|
||||||
raise UsageError(
|
raise UsageError("Wrong expression passed to '-m': {}".format(markexpr))
|
||||||
"Marker expression provided to -m:{} was not valid python syntax."
|
|
||||||
" Please check the syntax provided and ensure it is correct".format(
|
|
||||||
markexpr
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def matchkeyword(colitem, keywordexpr):
|
def matchkeyword(colitem, keywordexpr):
|
||||||
|
|
|
@ -601,21 +601,6 @@ class TestFunctional:
|
||||||
deselected_tests = dlist[0].items
|
deselected_tests = dlist[0].items
|
||||||
assert len(deselected_tests) == 2
|
assert len(deselected_tests) == 2
|
||||||
|
|
||||||
def test_invalid_m_option(self, testdir):
|
|
||||||
testdir.makepyfile(
|
|
||||||
"""
|
|
||||||
def test_a():
|
|
||||||
pass
|
|
||||||
"""
|
|
||||||
)
|
|
||||||
expected = (
|
|
||||||
"ERROR: Marker expression provided to -m: bogus/ was not valid python syntax. Please "
|
|
||||||
"check the syntax provided and ensure it is correct"
|
|
||||||
)
|
|
||||||
result = testdir.runpytest("-m bogus/")
|
|
||||||
result.stderr.fnmatch_lines([expected])
|
|
||||||
assert result.ret == ExitCode.USAGE_ERROR
|
|
||||||
|
|
||||||
def test_keywords_at_node_level(self, testdir):
|
def test_keywords_at_node_level(self, testdir):
|
||||||
testdir.makepyfile(
|
testdir.makepyfile(
|
||||||
"""
|
"""
|
||||||
|
@ -1027,7 +1012,8 @@ def test_pytest_param_id_allows_none_or_string(s):
|
||||||
assert pytest.param(id=s)
|
assert pytest.param(id=s)
|
||||||
|
|
||||||
|
|
||||||
def test_ux_eval_syntax_error(testdir):
|
@pytest.mark.parametrize("expr", ("NOT internal_err", "NOT (internal_err)", "bogus/"))
|
||||||
|
def test_marker_expr_eval_failure_handling(testdir, expr):
|
||||||
foo = testdir.makepyfile(
|
foo = testdir.makepyfile(
|
||||||
"""
|
"""
|
||||||
import pytest
|
import pytest
|
||||||
|
@ -1037,29 +1023,7 @@ def test_ux_eval_syntax_error(testdir):
|
||||||
pass
|
pass
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
expected = (
|
expected = "ERROR: Wrong expression passed to '-m': {}".format(expr)
|
||||||
"ERROR: Marker expression provided to -m: NOT internal_err was not valid python syntax. Please "
|
result = testdir.runpytest(foo, "-m", expr)
|
||||||
"check the syntax provided and ensure it is correct"
|
|
||||||
)
|
|
||||||
result = testdir.runpytest(foo, "-m NOT internal_err")
|
|
||||||
result.stderr.fnmatch_lines([expected])
|
|
||||||
assert result.ret == ExitCode.USAGE_ERROR
|
|
||||||
|
|
||||||
|
|
||||||
def test_ux_eval_type_error(testdir):
|
|
||||||
foo = testdir.makepyfile(
|
|
||||||
"""
|
|
||||||
import pytest
|
|
||||||
|
|
||||||
@pytest.mark.internal_err
|
|
||||||
def test_foo():
|
|
||||||
pass
|
|
||||||
"""
|
|
||||||
)
|
|
||||||
expected = (
|
|
||||||
"ERROR: Marker expression provided to -m: NOT (internal_err) was not valid python syntax. Please "
|
|
||||||
"check the syntax provided and ensure it is correct"
|
|
||||||
)
|
|
||||||
result = testdir.runpytest(foo, "-m NOT (internal_err)")
|
|
||||||
result.stderr.fnmatch_lines([expected])
|
result.stderr.fnmatch_lines([expected])
|
||||||
assert result.ret == ExitCode.USAGE_ERROR
|
assert result.ret == ExitCode.USAGE_ERROR
|
||||||
|
|
Loading…
Reference in New Issue