From 5322f057a05252457b4f47ffdc3fa0538fa9ca7e Mon Sep 17 00:00:00 2001 From: holger krekel Date: Thu, 21 Nov 2013 09:26:45 +0100 Subject: [PATCH] move two fixture test modules into bigger testing/python/fixture.py --- testing/python/fixture.py | 56 ++++++++++++++++++++++++++++++- testing/test_fixture_finalizer.py | 31 ----------------- testing/test_fixture_scope.py | 28 ---------------- 3 files changed, 55 insertions(+), 60 deletions(-) delete mode 100644 testing/test_fixture_finalizer.py delete mode 100644 testing/test_fixture_scope.py diff --git a/testing/python/fixture.py b/testing/python/fixture.py index 97ad805c7..15d5e955a 100644 --- a/testing/python/fixture.py +++ b/testing/python/fixture.py @@ -2,7 +2,7 @@ import pytest, py, sys from _pytest import python as funcargs from _pytest.python import FixtureLookupError from _pytest.pytester import get_public_names - +from textwrap import dedent def test_getfuncargnames(): def f(): pass @@ -1738,6 +1738,60 @@ class TestFixtureMarker: """) assert "error" not in result.stdout.str() + def test_fixture_finalizer(self, testdir): + testdir.makeconftest(""" + import pytest + import sys + + @pytest.fixture + def browser(request): + + def finalize(): + sys.stdout.write('Finalized') + request.addfinalizer(finalize) + return {} + """) + b = testdir.mkdir("subdir") + b.join("test_overriden_fixture_finalizer.py").write(dedent(""" + import pytest + @pytest.fixture + def browser(browser): + browser['visited'] = True + return browser + + def test_browser(browser): + assert browser['visited'] is True + """)) + reprec = testdir.runpytest("-s") + for test in ['test_browser']: + reprec.stdout.fnmatch_lines('*Finalized*') + + def test_class_scope_with_normal_tests(self, testdir): + testpath = testdir.makepyfile(""" + import pytest + + class Box: + value = 0 + + @pytest.fixture(scope='class') + def a(request): + Box.value += 1 + return Box.value + + def test_a(a): + assert a == 1 + + class Test1: + def test_b(self, a): + assert a == 2 + + class Test2: + def test_c(self, a): + assert a == 3""") + reprec = testdir.inline_run(testpath) + for test in ['test_a', 'test_b', 'test_c']: + assert reprec.matchreport(test).passed + def test_parametrize_separated_lifecycle(self, testdir): testdir.makepyfile(""" import pytest diff --git a/testing/test_fixture_finalizer.py b/testing/test_fixture_finalizer.py deleted file mode 100644 index 3126d140a..000000000 --- a/testing/test_fixture_finalizer.py +++ /dev/null @@ -1,31 +0,0 @@ -"""Tests for fixtures with different scoping.""" -import py.code - - -def test_fixture_finalizer(testdir): - testdir.makeconftest(""" - import pytest - import sys - - @pytest.fixture - def browser(request): - - def finalize(): - sys.stdout.write('Finalized') - request.addfinalizer(finalize) - return {} - """) - b = testdir.mkdir("subdir") - b.join("test_overriden_fixture_finalizer.py").write(py.code.Source(""" - import pytest - @pytest.fixture - def browser(browser): - browser['visited'] = True - return browser - - def test_browser(browser): - assert browser['visited'] is True - """)) - reprec = testdir.runpytest("-s") - for test in ['test_browser']: - reprec.stdout.fnmatch_lines('*Finalized*') diff --git a/testing/test_fixture_scope.py b/testing/test_fixture_scope.py deleted file mode 100644 index 0bd8c5206..000000000 --- a/testing/test_fixture_scope.py +++ /dev/null @@ -1,28 +0,0 @@ -"""Tests for fixtures with different scoping.""" - - -def test_class_scope_with_normal_tests(testdir): - testpath = testdir.makepyfile(""" - import pytest - - class Box: - value = 0 - - @pytest.fixture(scope='class') - def a(request): - Box.value += 1 - return Box.value - - def test_a(a): - assert a == 1 - - class Test1: - def test_b(self, a): - assert a == 2 - - class Test2: - def test_c(self, a): - assert a == 3""") - reprec = testdir.inline_run(testpath) - for test in ['test_a', 'test_b', 'test_c']: - assert reprec.matchreport(test).passed