<div dir="ltr">well, then it contradicts with the grouping efforts Holger mentioned<div>but personally i do like the simplicity, which always works</div><div>so by removing the grouping we can solve real-life issue</div><div>BTW: what was the actual reason for the grouping efforts?</div></div><div class="gmail_extra"><br><div class="gmail_quote">On 23 September 2014 00:54, Ronny Pfannschmidt <span dir="ltr"><<a href="mailto:ich@ronnypfannschmidt.de" target="_blank">ich@ronnypfannschmidt.de</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div>The current semantic is teardown on leaving the scope, I don't think anything else makes more sense<br>
<br>
At least I'm not convinced usage dependent teardown is a good idea<br>
<br>
<font color="#888888"><font color="#888888">Sent from my android device.</font></font><div><div class="h5"><br><br>-----Original Message-----<br>From: Anatoly Bubenkov <<a href="mailto:bubenkoff@gmail.com" target="_blank">bubenkoff@gmail.com</a>><br>To: Andreas Pelme <<a href="mailto:andreas@pelme.se" target="_blank">andreas@pelme.se</a>><br>Cc: pytest-dev <<a href="mailto:pytest-dev@python.org" target="_blank">pytest-dev@python.org</a>><br>Sent: Mo., 22 Sep. 2014 22:31<br>Subject: Re: [pytest-dev] pytest-xdist-1.11: restarting crash nodes, fixture cache fix<br><br></div></div></div><div class="HOEnZb"><div class="h5"><p dir="ltr">+1 for making tear downs consistent and clear for all the scopes<br>
Having teardown argument solves it to me</p>
<div class="gmail_quote">On Sep 22, 2014 10:03 PM, "Andreas Pelme" <<a href="mailto:andreas@pelme.se" target="_blank">andreas@pelme.se</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Holger,<br>
<br>
On 19 sep 2014, at 09:52, holger krekel <<a href="mailto:holger@merlinux.eu" target="_blank">holger@merlinux.eu</a>> wrote:<br>
> I presume that with module and class scope people don't presume that<br>
> a fixture survives until the end of a process so eager teardown is less<br>
> of a problem, there, right?<br>
<br>
<br>
I have not fully grasped how fixture teardown currently happens in pytest. To explore it, I came up with this example:<br>
<br>
import pytest<br>
<br>
<br>
@pytest.yield_fixture(scope='class')<br>
def fix():<br>
print 'fixture setup'<br>
yield<br>
print 'fixture teardown'<br>
<br>
<br>
<br>
class TestFoo():<br>
def test_a(self, fix):<br>
print 'test_a'<br>
<br>
def test_b(self):<br>
print 'test_b'<br>
<br>
def test_c(self, fix):<br>
print 'test_c'<br>
<br>
<br>
It gives me the output (with the latest pytest from PyPI):<br>
<br>
fixture setup<br>
test_a<br>
test_b<br>
test_c<br>
fixture teardown<br>
<br>
I.e. even though test_b does not actively request the fixture, it is active during the test.<br>
<br>
Is this even considered to be a bug or a feature? :-) This behavior may be considered a bug since it makes test suites brittle - if the fixture does not contain a value itself, it can probably be neglected to actually properly request the fixture, but test_b will still accidentally have “fix” available. Bugs like this will only show itself when running a subset of the test suite (and with xdist!).<br>
<br>
I would prefer (I think) if all fixtures where torn down when they are not requested (in my example, before test_b is run, to ensure test_b is only run with its own fixtures).<br>
<br>
However, if all teardowns worked like this, the efficiency will be very bad since there will be a lot of teardowns. I think these fixtures that should be allowed to stay alive, should be explicitly declared like that, like the option to pytest.fixture() suggested earlier.<br>
<br>
I think this makes sense regardless of whether the fixture is class, module or session scoped. Having different semantics depending on the scope would be confusing. Fixture authors must be aware and decide whether or not a fixture may accidentally be available to wrong tests. I have a hard time to see how we can solve this properly without a flag or some kind of distinction for this.<br>
<br>
I am probably missing a lot of details here, what are your thoughts on this?<br>
<br>
Cheers,<br>
Andreas<br>
<br>
</blockquote></div>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br><div dir="ltr">Anatoly Bubenkov<br></div>
</div>