From 722b35b0a63ee7ea2655056378ede6ad159e0e3a Mon Sep 17 00:00:00 2001 From: Anatoly Bubenkov Date: Wed, 14 Aug 2013 13:58:59 +0200 Subject: [PATCH] tests for fixture finalizers --HG-- branch : overriden-fixture-finalizer --- testing/test_fixture_finalizer.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 testing/test_fixture_finalizer.py diff --git a/testing/test_fixture_finalizer.py b/testing/test_fixture_finalizer.py new file mode 100644 index 000000000..911647819 --- /dev/null +++ b/testing/test_fixture_finalizer.py @@ -0,0 +1,30 @@ +"""Tests for fixtures with different scoping.""" +import py.code + + +def test_fixture_finalizer(testdir): + testdir.makeconftest(""" + import pytest + + @pytest.fixture + def browser(request): + + def finalize(): + print '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')