[pytest-dev] Unexpected fixture behaviour.

Anton P anton7811 at gmail.com
Mon Apr 7 12:43:48 CEST 2014


Hi All,

Recently we switched our test environment from funcargs to fixtures and
found unexpected and unwanted behaviour: In case fixture finalizer failed
next time fixture won't be set up.

Here I have 2 fixtures:
env_main - module level
env - functional level (env_main child)

In pytest output you can see message that env was created before test_1
("INIT_ENV" message). Then it failed on finalizer after "DESTROY ENV"
message.
PROBLEM: test_2 that requires env fixture is launched but without env
fixture.
I expect that function level fixture will be recreated for the next test
function, or at least all other test functions will fail without launching.
I don't see any reason why they have to be launched in case fixture cannot
be set up. But it's better to try to recreate fixture for next iteration
(e.g. next function if scope is function)

I see there was an issue #287 which is marked as resolved. But as for me it
could be reopened.

I see that in case we add more test cases, then the fixture will be created
for the 3d test function but again skipped for the 4th test function.

Is it possible to change current default behaviour?

Thank you in advance!
Anton

P.S.
Please find code files attached.

Here is execution log:

$ py.test -v -s test_params.py
============================ test session starts
============================
platform linux2 -- Python 2.7.3 -- py-1.4.20 -- pytest-2.5.2 --
/usr/bin/python
plugins: cov
collected 2 items

test_params.py:4: TestClass.test_1 Create ENV_MAIN
INIT ENV
PASSEDDESTROY ENV

test_params.py:4: TestClass.test_1 ERROR
test_params.py:7: TestClass.test_2 PASSEDDestroy ENV_MAIN


================================== ERRORS
===================================
___________________ ERROR at teardown of TestClass.test_1
___________________

self = <conftest.EnvTest instance at 0x2025878>

    def teardown(self):
        print "DESTROY ENV"
>       assert 0
E       assert 0

conftest.py:30: AssertionError
===================== 2 passed, 1 error in 0.01 seconds
=====================
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/pytest-dev/attachments/20140407/18795a0b/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: conftest.py
Type: text/x-python
Size: 898 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/pytest-dev/attachments/20140407/18795a0b/attachment.py>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test_params.py
Type: text/x-python
Size: 115 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/pytest-dev/attachments/20140407/18795a0b/attachment-0001.py>


More information about the Pytest-dev mailing list