remove test file formatting from TestContextManagerFixtureFuncs
This commit is contained in:
parent
e9371a58a0
commit
7845ab4bc3
|
@ -3462,25 +3462,40 @@ class TestShowFixtures(object):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("flavor", ["fixture", "yield_fixture"])
|
|
||||||
class TestContextManagerFixtureFuncs(object):
|
class TestContextManagerFixtureFuncs(object):
|
||||||
|
@pytest.fixture(params=["fixture", "yield_fixture"])
|
||||||
|
def flavor(self, request, testdir, monkeypatch):
|
||||||
|
monkeypatch.setenv("PYTEST_FIXTURE_FLAVOR", request.param)
|
||||||
|
testdir.makepyfile(
|
||||||
|
test_context="""
|
||||||
|
import os
|
||||||
|
import pytest
|
||||||
|
import warnings
|
||||||
|
VAR = "PYTEST_FIXTURE_FLAVOR"
|
||||||
|
if VAR not in os.environ:
|
||||||
|
warnings.warn("PYTEST_FIXTURE_FLAVOR was not set, assuming fixture")
|
||||||
|
fixture = pytest.fixture
|
||||||
|
else:
|
||||||
|
fixture = getattr(pytest, os.environ[VAR])
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
|
||||||
def test_simple(self, testdir, flavor):
|
def test_simple(self, testdir, flavor):
|
||||||
testdir.makepyfile(
|
testdir.makepyfile(
|
||||||
"""
|
"""
|
||||||
import pytest
|
from __future__ import print_function
|
||||||
@pytest.{flavor}
|
from test_context import fixture
|
||||||
|
@fixture
|
||||||
def arg1():
|
def arg1():
|
||||||
print ("setup")
|
print ("setup")
|
||||||
yield 1
|
yield 1
|
||||||
print ("teardown")
|
print ("teardown")
|
||||||
def test_1(arg1):
|
def test_1(arg1):
|
||||||
print ("test1 %s" % arg1)
|
print ("test1", arg1)
|
||||||
def test_2(arg1):
|
def test_2(arg1):
|
||||||
print ("test2 %s" % arg1)
|
print ("test2", arg1)
|
||||||
assert 0
|
assert 0
|
||||||
""".format(
|
"""
|
||||||
flavor=flavor
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
result = testdir.runpytest("-s")
|
result = testdir.runpytest("-s")
|
||||||
result.stdout.fnmatch_lines(
|
result.stdout.fnmatch_lines(
|
||||||
|
@ -3497,19 +3512,18 @@ class TestContextManagerFixtureFuncs(object):
|
||||||
def test_scoped(self, testdir, flavor):
|
def test_scoped(self, testdir, flavor):
|
||||||
testdir.makepyfile(
|
testdir.makepyfile(
|
||||||
"""
|
"""
|
||||||
import pytest
|
from __future__ import print_function
|
||||||
@pytest.{flavor}(scope="module")
|
from test_context import fixture
|
||||||
|
@fixture(scope="module")
|
||||||
def arg1():
|
def arg1():
|
||||||
print ("setup")
|
print ("setup")
|
||||||
yield 1
|
yield 1
|
||||||
print ("teardown")
|
print ("teardown")
|
||||||
def test_1(arg1):
|
def test_1(arg1):
|
||||||
print ("test1 %s" % arg1)
|
print ("test1", arg1)
|
||||||
def test_2(arg1):
|
def test_2(arg1):
|
||||||
print ("test2 %s" % arg1)
|
print ("test2", arg1)
|
||||||
""".format(
|
"""
|
||||||
flavor=flavor
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
result = testdir.runpytest("-s")
|
result = testdir.runpytest("-s")
|
||||||
result.stdout.fnmatch_lines(
|
result.stdout.fnmatch_lines(
|
||||||
|
@ -3524,16 +3538,14 @@ class TestContextManagerFixtureFuncs(object):
|
||||||
def test_setup_exception(self, testdir, flavor):
|
def test_setup_exception(self, testdir, flavor):
|
||||||
testdir.makepyfile(
|
testdir.makepyfile(
|
||||||
"""
|
"""
|
||||||
import pytest
|
from test_context import fixture
|
||||||
@pytest.{flavor}(scope="module")
|
@fixture(scope="module")
|
||||||
def arg1():
|
def arg1():
|
||||||
pytest.fail("setup")
|
pytest.fail("setup")
|
||||||
yield 1
|
yield 1
|
||||||
def test_1(arg1):
|
def test_1(arg1):
|
||||||
pass
|
pass
|
||||||
""".format(
|
"""
|
||||||
flavor=flavor
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
result = testdir.runpytest("-s")
|
result = testdir.runpytest("-s")
|
||||||
result.stdout.fnmatch_lines(
|
result.stdout.fnmatch_lines(
|
||||||
|
@ -3546,16 +3558,14 @@ class TestContextManagerFixtureFuncs(object):
|
||||||
def test_teardown_exception(self, testdir, flavor):
|
def test_teardown_exception(self, testdir, flavor):
|
||||||
testdir.makepyfile(
|
testdir.makepyfile(
|
||||||
"""
|
"""
|
||||||
import pytest
|
from test_context import fixture
|
||||||
@pytest.{flavor}(scope="module")
|
@fixture(scope="module")
|
||||||
def arg1():
|
def arg1():
|
||||||
yield 1
|
yield 1
|
||||||
pytest.fail("teardown")
|
pytest.fail("teardown")
|
||||||
def test_1(arg1):
|
def test_1(arg1):
|
||||||
pass
|
pass
|
||||||
""".format(
|
"""
|
||||||
flavor=flavor
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
result = testdir.runpytest("-s")
|
result = testdir.runpytest("-s")
|
||||||
result.stdout.fnmatch_lines(
|
result.stdout.fnmatch_lines(
|
||||||
|
@ -3568,8 +3578,8 @@ class TestContextManagerFixtureFuncs(object):
|
||||||
def test_yields_more_than_one(self, testdir, flavor):
|
def test_yields_more_than_one(self, testdir, flavor):
|
||||||
testdir.makepyfile(
|
testdir.makepyfile(
|
||||||
"""
|
"""
|
||||||
import pytest
|
from test_context import fixture
|
||||||
@pytest.{flavor}(scope="module")
|
@fixture(scope="module")
|
||||||
def arg1():
|
def arg1():
|
||||||
yield 1
|
yield 1
|
||||||
yield 2
|
yield 2
|
||||||
|
@ -3590,15 +3600,13 @@ class TestContextManagerFixtureFuncs(object):
|
||||||
def test_custom_name(self, testdir, flavor):
|
def test_custom_name(self, testdir, flavor):
|
||||||
testdir.makepyfile(
|
testdir.makepyfile(
|
||||||
"""
|
"""
|
||||||
import pytest
|
from test_context import fixture
|
||||||
@pytest.{flavor}(name='meow')
|
@fixture(name='meow')
|
||||||
def arg1():
|
def arg1():
|
||||||
return 'mew'
|
return 'mew'
|
||||||
def test_1(meow):
|
def test_1(meow):
|
||||||
print(meow)
|
print(meow)
|
||||||
""".format(
|
"""
|
||||||
flavor=flavor
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
result = testdir.runpytest("-s")
|
result = testdir.runpytest("-s")
|
||||||
result.stdout.fnmatch_lines("*mew*")
|
result.stdout.fnmatch_lines("*mew*")
|
||||||
|
|
Loading…
Reference in New Issue