Open AlessandroMiola opened 6 months ago
@AlessandroMiola, I agree! For me it would be better something like...
import pytest
class TestAttribute:
@pytest.fixture(autouse=True)
def set_attribute(self):
self.attribute = True
def test_autouse_fixture(self):
assert self.attribute
def test_autouse_fixture_again(self):
assert self.attribute
Hi Eric :) first off, congrats for maintaining such an amazing blog on
pytest
features. I'm gradually going through all of the posts: they're great!As for the
autouse
internals, some doubts did arise. I'd like to ask you whether you could shed some light on the following:at times (see
test/test_number_conversions.py
ortest/test_combining_autouse_with_normal.py
etc.) it seems that specifyingautouse=True
is irrelevant as you would get the test passed as well by omitting it (as long as you pass the fixture to other fixtures or to test functions); said differently, it is not crystal clear (to me) where's the advantage in specifyingautouse=True
in situations where not explicitly passing the fixture (to other fixtures or to test functions) would eventually lead to a failureif I were to infer the meaning of
autouse=True
before reading your post, I would have said that it would have helped eliminating the need for manual fixture invocation (which I would have read as the opportunity to avoid manually passing fixtures to test functions or other fixtures) in specific situations; as it doesn't seem to be the case, can you elaborate more on the rationale behind it? Not even the docs do make it clear (to me at least :))