Merge remote-tracking branch 'origin/master' into mm
This commit is contained in:
@@ -146,7 +146,24 @@ class TestClass(object):
|
||||
result = testdir.runpytest("-rw")
|
||||
result.stdout.fnmatch_lines(
|
||||
[
|
||||
"*cannot collect test class 'TestClass1' because it has a __init__ constructor"
|
||||
"*cannot collect test class 'TestClass1' because it has "
|
||||
"a __init__ constructor (from: test_class_with_init_warning.py)"
|
||||
]
|
||||
)
|
||||
|
||||
def test_class_with_new_warning(self, testdir):
|
||||
testdir.makepyfile(
|
||||
"""
|
||||
class TestClass1(object):
|
||||
def __new__(self):
|
||||
pass
|
||||
"""
|
||||
)
|
||||
result = testdir.runpytest("-rw")
|
||||
result.stdout.fnmatch_lines(
|
||||
[
|
||||
"*cannot collect test class 'TestClass1' because it has "
|
||||
"a __new__ constructor (from: test_class_with_new_warning.py)"
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
@@ -3950,3 +3950,46 @@ def test_call_fixture_function_error():
|
||||
|
||||
with pytest.raises(pytest.fail.Exception):
|
||||
assert fix() == 1
|
||||
|
||||
|
||||
def test_fixture_param_shadowing(testdir):
|
||||
"""Parametrized arguments would be shadowed if a fixture with the same name also exists (#5036)"""
|
||||
testdir.makepyfile(
|
||||
"""
|
||||
import pytest
|
||||
|
||||
@pytest.fixture(params=['a', 'b'])
|
||||
def argroot(request):
|
||||
return request.param
|
||||
|
||||
@pytest.fixture
|
||||
def arg(argroot):
|
||||
return argroot
|
||||
|
||||
# This should only be parametrized directly
|
||||
@pytest.mark.parametrize("arg", [1])
|
||||
def test_direct(arg):
|
||||
assert arg == 1
|
||||
|
||||
# This should be parametrized based on the fixtures
|
||||
def test_normal_fixture(arg):
|
||||
assert isinstance(arg, str)
|
||||
|
||||
# Indirect should still work:
|
||||
|
||||
@pytest.fixture
|
||||
def arg2(request):
|
||||
return 2*request.param
|
||||
|
||||
@pytest.mark.parametrize("arg2", [1], indirect=True)
|
||||
def test_indirect(arg2):
|
||||
assert arg2 == 2
|
||||
"""
|
||||
)
|
||||
# Only one test should have run
|
||||
result = testdir.runpytest("-v")
|
||||
result.assert_outcomes(passed=4)
|
||||
result.stdout.fnmatch_lines(["*::test_direct[[]1[]]*"])
|
||||
result.stdout.fnmatch_lines(["*::test_normal_fixture[[]a[]]*"])
|
||||
result.stdout.fnmatch_lines(["*::test_normal_fixture[[]b[]]*"])
|
||||
result.stdout.fnmatch_lines(["*::test_indirect[[]1[]]*"])
|
||||
|
||||
Reference in New Issue
Block a user