Merge pull request #4077 from nicoddemus/short-usage-errors
Improve internal error messages
This commit is contained in:
@@ -1217,8 +1217,7 @@ class TestFixtureUsages(object):
|
||||
result = testdir.runpytest_inprocess()
|
||||
result.stdout.fnmatch_lines(
|
||||
(
|
||||
"*ValueError: fixture badscope from test_invalid_scope.py has an unsupported"
|
||||
" scope value 'functions'"
|
||||
"*Fixture 'badscope' from test_invalid_scope.py got an unexpected scope value 'functions'"
|
||||
)
|
||||
)
|
||||
|
||||
@@ -3607,16 +3606,15 @@ class TestParameterizedSubRequest(object):
|
||||
)
|
||||
result = testdir.runpytest()
|
||||
result.stdout.fnmatch_lines(
|
||||
"""
|
||||
E*Failed: The requested fixture has no parameter defined for test:
|
||||
E* test_call_from_fixture.py::test_foo
|
||||
E*
|
||||
E*Requested fixture 'fix_with_param' defined in:
|
||||
E*test_call_from_fixture.py:4
|
||||
E*Requested here:
|
||||
E*test_call_from_fixture.py:9
|
||||
*1 error*
|
||||
"""
|
||||
[
|
||||
"The requested fixture has no parameter defined for test:",
|
||||
" test_call_from_fixture.py::test_foo",
|
||||
"Requested fixture 'fix_with_param' defined in:",
|
||||
"test_call_from_fixture.py:4",
|
||||
"Requested here:",
|
||||
"test_call_from_fixture.py:9",
|
||||
"*1 error in*",
|
||||
]
|
||||
)
|
||||
|
||||
def test_call_from_test(self, testdir):
|
||||
@@ -3634,16 +3632,15 @@ class TestParameterizedSubRequest(object):
|
||||
)
|
||||
result = testdir.runpytest()
|
||||
result.stdout.fnmatch_lines(
|
||||
"""
|
||||
E*Failed: The requested fixture has no parameter defined for test:
|
||||
E* test_call_from_test.py::test_foo
|
||||
E*
|
||||
E*Requested fixture 'fix_with_param' defined in:
|
||||
E*test_call_from_test.py:4
|
||||
E*Requested here:
|
||||
E*test_call_from_test.py:8
|
||||
*1 failed*
|
||||
"""
|
||||
[
|
||||
"The requested fixture has no parameter defined for test:",
|
||||
" test_call_from_test.py::test_foo",
|
||||
"Requested fixture 'fix_with_param' defined in:",
|
||||
"test_call_from_test.py:4",
|
||||
"Requested here:",
|
||||
"test_call_from_test.py:8",
|
||||
"*1 failed*",
|
||||
]
|
||||
)
|
||||
|
||||
def test_external_fixture(self, testdir):
|
||||
@@ -3665,16 +3662,16 @@ class TestParameterizedSubRequest(object):
|
||||
)
|
||||
result = testdir.runpytest()
|
||||
result.stdout.fnmatch_lines(
|
||||
"""
|
||||
E*Failed: The requested fixture has no parameter defined for test:
|
||||
E* test_external_fixture.py::test_foo
|
||||
E*
|
||||
E*Requested fixture 'fix_with_param' defined in:
|
||||
E*conftest.py:4
|
||||
E*Requested here:
|
||||
E*test_external_fixture.py:2
|
||||
*1 failed*
|
||||
"""
|
||||
[
|
||||
"The requested fixture has no parameter defined for test:",
|
||||
" test_external_fixture.py::test_foo",
|
||||
"",
|
||||
"Requested fixture 'fix_with_param' defined in:",
|
||||
"conftest.py:4",
|
||||
"Requested here:",
|
||||
"test_external_fixture.py:2",
|
||||
"*1 failed*",
|
||||
]
|
||||
)
|
||||
|
||||
def test_non_relative_path(self, testdir):
|
||||
@@ -3709,16 +3706,16 @@ class TestParameterizedSubRequest(object):
|
||||
testdir.syspathinsert(fixdir)
|
||||
result = testdir.runpytest()
|
||||
result.stdout.fnmatch_lines(
|
||||
"""
|
||||
E*Failed: The requested fixture has no parameter defined for test:
|
||||
E* test_foos.py::test_foo
|
||||
E*
|
||||
E*Requested fixture 'fix_with_param' defined in:
|
||||
E*fix.py:4
|
||||
E*Requested here:
|
||||
E*test_foos.py:4
|
||||
*1 failed*
|
||||
"""
|
||||
[
|
||||
"The requested fixture has no parameter defined for test:",
|
||||
" test_foos.py::test_foo",
|
||||
"",
|
||||
"Requested fixture 'fix_with_param' defined in:",
|
||||
"*fix.py:4",
|
||||
"Requested here:",
|
||||
"test_foos.py:4",
|
||||
"*1 failed*",
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -127,10 +127,11 @@ class TestMetafunc(object):
|
||||
pass
|
||||
|
||||
metafunc = self.Metafunc(func)
|
||||
try:
|
||||
with pytest.raises(
|
||||
pytest.fail.Exception,
|
||||
match=r"parametrize\(\) call in func got an unexpected scope value 'doggy'",
|
||||
):
|
||||
metafunc.parametrize("x", [1], scope="doggy")
|
||||
except ValueError as ve:
|
||||
assert "has an unsupported scope value 'doggy'" in str(ve)
|
||||
|
||||
def test_find_parametrized_scope(self):
|
||||
"""unittest for _find_parametrized_scope (#3941)"""
|
||||
@@ -206,16 +207,13 @@ class TestMetafunc(object):
|
||||
|
||||
metafunc = self.Metafunc(func)
|
||||
|
||||
pytest.raises(
|
||||
ValueError, lambda: metafunc.parametrize("x", [1, 2], ids=["basic"])
|
||||
)
|
||||
with pytest.raises(pytest.fail.Exception):
|
||||
metafunc.parametrize("x", [1, 2], ids=["basic"])
|
||||
|
||||
pytest.raises(
|
||||
ValueError,
|
||||
lambda: metafunc.parametrize(
|
||||
with pytest.raises(pytest.fail.Exception):
|
||||
metafunc.parametrize(
|
||||
("x", "y"), [("abc", "def"), ("ghi", "jkl")], ids=["one"]
|
||||
),
|
||||
)
|
||||
)
|
||||
|
||||
@pytest.mark.issue510
|
||||
def test_parametrize_empty_list(self):
|
||||
@@ -573,7 +571,7 @@ class TestMetafunc(object):
|
||||
pass
|
||||
|
||||
metafunc = self.Metafunc(func)
|
||||
with pytest.raises(ValueError):
|
||||
with pytest.raises(pytest.fail.Exception):
|
||||
metafunc.parametrize("x, y", [("a", "b")], indirect=["x", "z"])
|
||||
|
||||
@pytest.mark.issue714
|
||||
@@ -1189,7 +1187,9 @@ class TestMetafuncFunctional(object):
|
||||
)
|
||||
result = testdir.runpytest()
|
||||
result.stdout.fnmatch_lines(
|
||||
["*ids must be list of strings, found: 2 (type: int)*"]
|
||||
[
|
||||
"*In test_ids_numbers: ids must be list of strings, found: 2 (type: *'int'>)*"
|
||||
]
|
||||
)
|
||||
|
||||
def test_parametrize_with_identical_ids_get_unique_names(self, testdir):
|
||||
@@ -1326,13 +1326,13 @@ class TestMetafuncFunctional(object):
|
||||
attr
|
||||
)
|
||||
)
|
||||
reprec = testdir.inline_run("--collectonly")
|
||||
failures = reprec.getfailures()
|
||||
assert len(failures) == 1
|
||||
expectederror = "MarkerError: test_foo has '{}', spelling should be 'parametrize'".format(
|
||||
attr
|
||||
result = testdir.runpytest("--collectonly")
|
||||
result.stdout.fnmatch_lines(
|
||||
[
|
||||
"test_foo has '{}' mark, spelling should be 'parametrize'".format(attr),
|
||||
"*1 error in*",
|
||||
]
|
||||
)
|
||||
assert expectederror in failures[0].longrepr.reprcrash.message
|
||||
|
||||
|
||||
class TestMetafuncFunctionalAuto(object):
|
||||
|
||||
@@ -247,7 +247,7 @@ def test_marker_without_description(testdir):
|
||||
)
|
||||
ftdir = testdir.mkdir("ft1_dummy")
|
||||
testdir.tmpdir.join("conftest.py").move(ftdir.join("conftest.py"))
|
||||
rec = testdir.runpytest_subprocess("--strict")
|
||||
rec = testdir.runpytest("--strict")
|
||||
rec.assert_outcomes()
|
||||
|
||||
|
||||
@@ -302,7 +302,7 @@ def test_strict_prohibits_unregistered_markers(testdir):
|
||||
)
|
||||
result = testdir.runpytest("--strict")
|
||||
assert result.ret != 0
|
||||
result.stdout.fnmatch_lines(["*unregisteredmark*not*registered*"])
|
||||
result.stdout.fnmatch_lines(["'unregisteredmark' not a registered marker"])
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
|
||||
@@ -570,7 +570,8 @@ def test_pytest_exit_msg(testdir):
|
||||
result.stderr.fnmatch_lines(["Exit: oh noes"])
|
||||
|
||||
|
||||
def test_pytest_fail_notrace(testdir):
|
||||
def test_pytest_fail_notrace_runtest(testdir):
|
||||
"""Test pytest.fail(..., pytrace=False) does not show tracebacks during test run."""
|
||||
testdir.makepyfile(
|
||||
"""
|
||||
import pytest
|
||||
@@ -585,6 +586,21 @@ def test_pytest_fail_notrace(testdir):
|
||||
assert "def teardown_function" not in result.stdout.str()
|
||||
|
||||
|
||||
def test_pytest_fail_notrace_collection(testdir):
|
||||
"""Test pytest.fail(..., pytrace=False) does not show tracebacks during collection."""
|
||||
testdir.makepyfile(
|
||||
"""
|
||||
import pytest
|
||||
def some_internal_function():
|
||||
pytest.fail("hello", pytrace=False)
|
||||
some_internal_function()
|
||||
"""
|
||||
)
|
||||
result = testdir.runpytest()
|
||||
result.stdout.fnmatch_lines(["hello"])
|
||||
assert "def some_internal_function()" not in result.stdout.str()
|
||||
|
||||
|
||||
@pytest.mark.parametrize("str_prefix", ["u", ""])
|
||||
def test_pytest_fail_notrace_non_ascii(testdir, str_prefix):
|
||||
"""Fix pytest.fail with pytrace=False with non-ascii characters (#1178).
|
||||
|
||||
Reference in New Issue
Block a user