Improve error message when TestCase functions use a parametrized fixture
Fix #2535
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
import pytest
|
||||
import unittest
|
||||
|
||||
|
||||
@pytest.fixture(params=[1, 2])
|
||||
def two(request):
|
||||
return request.param
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("two")
|
||||
class TestSomethingElse(unittest.TestCase):
|
||||
def test_two(self):
|
||||
pass
|
||||
@@ -3600,7 +3600,8 @@ class TestParameterizedSubRequest(object):
|
||||
result = testdir.runpytest()
|
||||
result.stdout.fnmatch_lines(
|
||||
"""
|
||||
E*Failed: The requested fixture has no parameter defined for the current test.
|
||||
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
|
||||
@@ -3626,7 +3627,8 @@ class TestParameterizedSubRequest(object):
|
||||
result = testdir.runpytest()
|
||||
result.stdout.fnmatch_lines(
|
||||
"""
|
||||
E*Failed: The requested fixture has no parameter defined for the current test.
|
||||
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
|
||||
@@ -3656,7 +3658,8 @@ class TestParameterizedSubRequest(object):
|
||||
result = testdir.runpytest()
|
||||
result.stdout.fnmatch_lines(
|
||||
"""
|
||||
E*Failed: The requested fixture has no parameter defined for the current test.
|
||||
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
|
||||
@@ -3699,7 +3702,8 @@ class TestParameterizedSubRequest(object):
|
||||
result = testdir.runpytest()
|
||||
result.stdout.fnmatch_lines(
|
||||
"""
|
||||
E*Failed: The requested fixture has no parameter defined for the current test.
|
||||
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
|
||||
|
||||
@@ -1010,3 +1010,15 @@ def test_testcase_handles_init_exceptions(testdir):
|
||||
result = testdir.runpytest()
|
||||
assert "should raise this exception" in result.stdout.str()
|
||||
assert "ERROR at teardown of MyTestCase.test_hello" not in result.stdout.str()
|
||||
|
||||
|
||||
def test_error_message_with_parametrized_fixtures(testdir):
|
||||
testdir.copy_example("unittest/test_parametrized_fixture_error_message.py")
|
||||
result = testdir.runpytest()
|
||||
result.stdout.fnmatch_lines(
|
||||
[
|
||||
"*test_two does not support fixtures*",
|
||||
"*TestSomethingElse::test_two",
|
||||
"*Function type: TestCaseFunction",
|
||||
]
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user