Pytest-with-Eric / pytest-fixture-autouse-example

How to Auto-Request Pytest Fixtures Using "Autouse"
https://pytest-with-eric.com/pytest-advanced/pytest-fixture-autouse/
0 stars 0 forks source link

[Question]: clarification on autouse fixture invocation #1

Open AlessandroMiola opened 6 months ago

AlessandroMiola commented 6 months ago

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:

Cliffart44 commented 2 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