Merged in parametrized-fixture-override (pull request #257)
allow to override parametrized fixtures with non-parametrized ones and vice versa
This commit is contained in:
@@ -393,14 +393,31 @@ class TestFunction:
|
||||
return 'value'
|
||||
|
||||
@pytest.mark.parametrize('value',
|
||||
['overrided'])
|
||||
def test_overrided_via_param(value):
|
||||
assert value == 'overrided'
|
||||
['overridden'])
|
||||
def test_overridden_via_param(value):
|
||||
assert value == 'overridden'
|
||||
""")
|
||||
rec = testdir.inline_run()
|
||||
rec.assertoutcome(passed=1)
|
||||
|
||||
|
||||
def test_parametrize_overrides_parametrized_fixture(self, testdir):
|
||||
"""Test parametrization when parameter overrides existing parametrized fixture with same name."""
|
||||
testdir.makepyfile("""
|
||||
import pytest
|
||||
|
||||
@pytest.fixture(params=[1, 2])
|
||||
def value(request):
|
||||
return request.param
|
||||
|
||||
@pytest.mark.parametrize('value',
|
||||
['overridden'])
|
||||
def test_overridden_via_param(value):
|
||||
assert value == 'overridden'
|
||||
""")
|
||||
rec = testdir.inline_run()
|
||||
rec.assertoutcome(passed=1)
|
||||
|
||||
def test_parametrize_with_mark(selfself, testdir):
|
||||
items = testdir.getitems("""
|
||||
import pytest
|
||||
|
||||
@@ -226,6 +226,114 @@ class TestFillFixtures:
|
||||
result = testdir.runpytest()
|
||||
assert result.ret == 0
|
||||
|
||||
def test_override_parametrized_fixture_conftest_module(self, testdir):
|
||||
"""Test override of the parametrized fixture with non-parametrized one on the test module level."""
|
||||
testdir.makeconftest("""
|
||||
import pytest
|
||||
|
||||
@pytest.fixture(params=[1, 2, 3])
|
||||
def spam(request):
|
||||
return request.param
|
||||
""")
|
||||
testfile = testdir.makepyfile("""
|
||||
import pytest
|
||||
|
||||
@pytest.fixture
|
||||
def spam():
|
||||
return 'spam'
|
||||
|
||||
def test_spam(spam):
|
||||
assert spam == 'spam'
|
||||
""")
|
||||
result = testdir.runpytest()
|
||||
result.stdout.fnmatch_lines(["*1 passed*"])
|
||||
result = testdir.runpytest(testfile)
|
||||
result.stdout.fnmatch_lines(["*1 passed*"])
|
||||
|
||||
def test_override_parametrized_fixture_conftest_conftest(self, testdir):
|
||||
"""Test override of the parametrized fixture with non-parametrized one on the conftest level."""
|
||||
testdir.makeconftest("""
|
||||
import pytest
|
||||
|
||||
@pytest.fixture(params=[1, 2, 3])
|
||||
def spam(request):
|
||||
return request.param
|
||||
""")
|
||||
subdir = testdir.mkpydir('subdir')
|
||||
subdir.join("conftest.py").write(py.code.Source("""
|
||||
import pytest
|
||||
|
||||
@pytest.fixture
|
||||
def spam():
|
||||
return 'spam'
|
||||
"""))
|
||||
testfile = subdir.join("test_spam.py")
|
||||
testfile.write(py.code.Source("""
|
||||
def test_spam(spam):
|
||||
assert spam == "spam"
|
||||
"""))
|
||||
result = testdir.runpytest()
|
||||
result.stdout.fnmatch_lines(["*1 passed*"])
|
||||
result = testdir.runpytest(testfile)
|
||||
result.stdout.fnmatch_lines(["*1 passed*"])
|
||||
|
||||
def test_override_non_parametrized_fixture_conftest_module(self, testdir):
|
||||
"""Test override of the non-parametrized fixture with parametrized one on the test module level."""
|
||||
testdir.makeconftest("""
|
||||
import pytest
|
||||
|
||||
@pytest.fixture
|
||||
def spam():
|
||||
return 'spam'
|
||||
""")
|
||||
testfile = testdir.makepyfile("""
|
||||
import pytest
|
||||
|
||||
@pytest.fixture(params=[1, 2, 3])
|
||||
def spam(request):
|
||||
return request.param
|
||||
|
||||
params = {'spam': 1}
|
||||
|
||||
def test_spam(spam):
|
||||
assert spam == params['spam']
|
||||
params['spam'] += 1
|
||||
""")
|
||||
result = testdir.runpytest()
|
||||
result.stdout.fnmatch_lines(["*3 passed*"])
|
||||
result = testdir.runpytest(testfile)
|
||||
result.stdout.fnmatch_lines(["*3 passed*"])
|
||||
|
||||
def test_override_non_parametrized_fixture_conftest_conftest(self, testdir):
|
||||
"""Test override of the non-parametrized fixture with parametrized one on the conftest level."""
|
||||
testdir.makeconftest("""
|
||||
import pytest
|
||||
|
||||
@pytest.fixture
|
||||
def spam():
|
||||
return 'spam'
|
||||
""")
|
||||
subdir = testdir.mkpydir('subdir')
|
||||
subdir.join("conftest.py").write(py.code.Source("""
|
||||
import pytest
|
||||
|
||||
@pytest.fixture(params=[1, 2, 3])
|
||||
def spam(request):
|
||||
return request.param
|
||||
"""))
|
||||
testfile = subdir.join("test_spam.py")
|
||||
testfile.write(py.code.Source("""
|
||||
params = {'spam': 1}
|
||||
|
||||
def test_spam(spam):
|
||||
assert spam == params['spam']
|
||||
params['spam'] += 1
|
||||
"""))
|
||||
result = testdir.runpytest()
|
||||
result.stdout.fnmatch_lines(["*3 passed*"])
|
||||
result = testdir.runpytest(testfile)
|
||||
result.stdout.fnmatch_lines(["*3 passed*"])
|
||||
|
||||
def test_autouse_fixture_plugin(self, testdir):
|
||||
# A fixture from a plugin has no baseid set, which screwed up
|
||||
# the autouse fixture handling.
|
||||
|
||||
Reference in New Issue
Block a user