remove test file formatting from TestContextManagerFixtureFuncs

This commit is contained in:
Ronny Pfannschmidt 2018-06-28 14:36:35 +02:00
parent e9371a58a0
commit 7845ab4bc3
1 changed files with 40 additions and 32 deletions

View File

@ -3462,25 +3462,40 @@ class TestShowFixtures(object):
pass
@pytest.mark.parametrize("flavor", ["fixture", "yield_fixture"])
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):
testdir.makepyfile(
"""
import pytest
@pytest.{flavor}
from __future__ import print_function
from test_context import fixture
@fixture
def arg1():
print ("setup")
yield 1
print ("teardown")
def test_1(arg1):
print ("test1 %s" % arg1)
print ("test1", arg1)
def test_2(arg1):
print ("test2 %s" % arg1)
print ("test2", arg1)
assert 0
""".format(
flavor=flavor
)
"""
)
result = testdir.runpytest("-s")
result.stdout.fnmatch_lines(
@ -3497,19 +3512,18 @@ class TestContextManagerFixtureFuncs(object):
def test_scoped(self, testdir, flavor):
testdir.makepyfile(
"""
import pytest
@pytest.{flavor}(scope="module")
from __future__ import print_function
from test_context import fixture
@fixture(scope="module")
def arg1():
print ("setup")
yield 1
print ("teardown")
def test_1(arg1):
print ("test1 %s" % arg1)
print ("test1", arg1)
def test_2(arg1):
print ("test2 %s" % arg1)
""".format(
flavor=flavor
)
print ("test2", arg1)
"""
)
result = testdir.runpytest("-s")
result.stdout.fnmatch_lines(
@ -3524,16 +3538,14 @@ class TestContextManagerFixtureFuncs(object):
def test_setup_exception(self, testdir, flavor):
testdir.makepyfile(
"""
import pytest
@pytest.{flavor}(scope="module")
from test_context import fixture
@fixture(scope="module")
def arg1():
pytest.fail("setup")
yield 1
def test_1(arg1):
pass
""".format(
flavor=flavor
)
"""
)
result = testdir.runpytest("-s")
result.stdout.fnmatch_lines(
@ -3546,16 +3558,14 @@ class TestContextManagerFixtureFuncs(object):
def test_teardown_exception(self, testdir, flavor):
testdir.makepyfile(
"""
import pytest
@pytest.{flavor}(scope="module")
from test_context import fixture
@fixture(scope="module")
def arg1():
yield 1
pytest.fail("teardown")
def test_1(arg1):
pass
""".format(
flavor=flavor
)
"""
)
result = testdir.runpytest("-s")
result.stdout.fnmatch_lines(
@ -3568,8 +3578,8 @@ class TestContextManagerFixtureFuncs(object):
def test_yields_more_than_one(self, testdir, flavor):
testdir.makepyfile(
"""
import pytest
@pytest.{flavor}(scope="module")
from test_context import fixture
@fixture(scope="module")
def arg1():
yield 1
yield 2
@ -3590,15 +3600,13 @@ class TestContextManagerFixtureFuncs(object):
def test_custom_name(self, testdir, flavor):
testdir.makepyfile(
"""
import pytest
@pytest.{flavor}(name='meow')
from test_context import fixture
@fixture(name='meow')
def arg1():
return 'mew'
def test_1(meow):
print(meow)
""".format(
flavor=flavor
)
"""
)
result = testdir.runpytest("-s")
result.stdout.fnmatch_lines("*mew*")