<div dir="ltr"><div><div><div>Hi Holger!<br><br></div>I saw your commit and patched pytest2.5.2 with it. It works in my case.<br><br></div>Thank you very much!<br></div>Anton<br></div><div class="gmail_extra"><br><br><div class="gmail_quote">
On Mon, Apr 7, 2014 at 2:00 PM, holger krekel <span dir="ltr"><<a href="mailto:holger@merlinux.eu" target="_blank">holger@merlinux.eu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi again,<br>
<div class=""><br>
On Mon, Apr 07, 2014 at 13:55 +0300, Anton P wrote:<br>
> Hi Holger,<br>
><br>
> Thank you for your response!<br>
><br>
> No, we haven't switched py.test versions. We just move all setup/teardown<br>
> procedures from pytest hooks to fixtures.<br>
><br>
> I'll update issue #498.<br>
<br>
</div>great, thanks. I think that in case of a failing finalizer a fixture<br>
might be marked as "broken" or so, and no attempt at re-creating it<br>
be made. Subsequent tests would not run (not sure how that gets reported<br>
exactly, though). Reporting a teardown error and then trying to<br>
recreate it might work in some cases but might also lead to even<br>
stranger errors because the fixture might still be half-setup<br>
due to the failed finalizer.<br>
<br>
best,<br>
holger<br>
<div class="HOEnZb"><div class="h5"><br>
<br>
> Thank you!<br>
> Anton<br>
><br>
><br>
> On Mon, Apr 7, 2014 at 1:51 PM, holger krekel <<a href="mailto:holger@merlinux.eu">holger@merlinux.eu</a>> wrote:<br>
><br>
> > Hi Anton,<br>
> ><br>
> > just to understand better -- you also switched pytest versions or not?<br>
> > A mere change from "pytest_funcarg__" syntax to "@pytest.fixture"<br>
> > syntax should not have such an effect.<br>
> ><br>
> > There also is issue498 which might be related, btw:<br>
> ><br>
> > <a href="https://bitbucket.org/hpk42/pytest/issue/498/function-scope-fixture-with-failing" target="_blank">https://bitbucket.org/hpk42/pytest/issue/498/function-scope-fixture-with-failing</a><br>
> ><br>
> > Could you file an issue against the tracker and/or add to 498?<br>
> ><br>
> > best and thanks,<br>
> ><br>
> > holger<br>
> ><br>
> > On Mon, Apr 07, 2014 at 13:43 +0300, Anton P wrote:<br>
> > > Hi All,<br>
> > ><br>
> > > Recently we switched our test environment from funcargs to fixtures and<br>
> > > found unexpected and unwanted behaviour: In case fixture finalizer failed<br>
> > > next time fixture won't be set up.<br>
> > ><br>
> > > Here I have 2 fixtures:<br>
> > > env_main - module level<br>
> > > env - functional level (env_main child)<br>
> > ><br>
> > > In pytest output you can see message that env was created before test_1<br>
> > > ("INIT_ENV" message). Then it failed on finalizer after "DESTROY ENV"<br>
> > > message.<br>
> > > PROBLEM: test_2 that requires env fixture is launched but without env<br>
> > > fixture.<br>
> > > I expect that function level fixture will be recreated for the next test<br>
> > > function, or at least all other test functions will fail without<br>
> > launching.<br>
> > > I don't see any reason why they have to be launched in case fixture<br>
> > cannot<br>
> > > be set up. But it's better to try to recreate fixture for next iteration<br>
> > > (e.g. next function if scope is function)<br>
> > ><br>
> > > I see there was an issue #287 which is marked as resolved. But as for me<br>
> > it<br>
> > > could be reopened.<br>
> > ><br>
> > > I see that in case we add more test cases, then the fixture will be<br>
> > created<br>
> > > for the 3d test function but again skipped for the 4th test function.<br>
> > ><br>
> > > Is it possible to change current default behaviour?<br>
> > ><br>
> > > Thank you in advance!<br>
> > > Anton<br>
> > ><br>
> > > P.S.<br>
> > > Please find code files attached.<br>
> > ><br>
> > > Here is execution log:<br>
> > ><br>
> > > $ py.test -v -s test_params.py<br>
> > > ============================ test session starts<br>
> > > ============================<br>
> > > platform linux2 -- Python 2.7.3 -- py-1.4.20 -- pytest-2.5.2 --<br>
> > > /usr/bin/python<br>
> > > plugins: cov<br>
> > > collected 2 items<br>
> > ><br>
> > > test_params.py:4: TestClass.test_1 Create ENV_MAIN<br>
> > > INIT ENV<br>
> > > PASSEDDESTROY ENV<br>
> > ><br>
> > > test_params.py:4: TestClass.test_1 ERROR<br>
> > > test_params.py:7: TestClass.test_2 PASSEDDestroy ENV_MAIN<br>
> > ><br>
> > ><br>
> > > ================================== ERRORS<br>
> > > ===================================<br>
> > > ___________________ ERROR at teardown of TestClass.test_1<br>
> > > ___________________<br>
> > ><br>
> > > self = <conftest.EnvTest instance at 0x2025878><br>
> > ><br>
> > > def teardown(self):<br>
> > > print "DESTROY ENV"<br>
> > > > assert 0<br>
> > > E assert 0<br>
> > ><br>
> > > conftest.py:30: AssertionError<br>
> > > ===================== 2 passed, 1 error in 0.01 seconds<br>
> > > =====================<br>
> ><br>
> > > import pytest<br>
> > > import sys<br>
> > ><br>
> > > class Env():<br>
> > > def __init__(self):<br>
> > > self.env = 1<br>
> > ><br>
> > > def create(self):<br>
> > > print "Create ENV_MAIN"<br>
> > ><br>
> > > return self.env<br>
> > ><br>
> > > def destroy(self):<br>
> > > print "Destroy ENV_MAIN"<br>
> > ><br>
> > ><br>
> > > class EnvTest():<br>
> > ><br>
> > > def __init__(self, request, env):<br>
> > > self.request = request<br>
> > > self.env = env<br>
> > > self.request.node.call_status = False<br>
> > ><br>
> > > def setup(self):<br>
> > > print "INIT ENV"<br>
> > > self.request.node.call_status = True<br>
> > ><br>
> > > def teardown(self):<br>
> > > print "DESTROY ENV"<br>
> > > assert 0<br>
> > ><br>
> > ><br>
> > ><br>
> > > @pytest.fixture(scope="module")<br>
> > > def env_main(request):<br>
> > > env_wrapper = Env()<br>
> > ><br>
> > > request.addfinalizer(env_wrapper.destroy)<br>
> > > request.config.env = env_wrapper.create()<br>
> > ><br>
> > > return env_wrapper<br>
> > ><br>
> > > @pytest.fixture<br>
> > > def env(request, env_main):<br>
> > > env = EnvTest(request, env_main)<br>
> > > request.addfinalizer(env.teardown)<br>
> > > env.setup()<br>
> > ><br>
> > > return env_main<br>
> ><br>
> > > import pytest<br>
> > ><br>
> > > class TestClass():<br>
> > > def test_1(self, env):<br>
> > > pass<br>
> > ><br>
> > > def test_2(self, env):<br>
> > > pass<br>
> ><br>
> > > _______________________________________________<br>
> > > Pytest-dev mailing list<br>
> > > <a href="mailto:Pytest-dev@python.org">Pytest-dev@python.org</a><br>
> > > <a href="https://mail.python.org/mailman/listinfo/pytest-dev" target="_blank">https://mail.python.org/mailman/listinfo/pytest-dev</a><br>
> ><br>
> ><br>
</div></div></blockquote></div><br></div>