-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Module fixture runs before session fixtures if redefined #8074
Comments
Related #5303 |
this output seems correct to me, the scope of a fixture doesn't always indicate its ordering as they are only instantiated as needed. the scope of the fixture determines the lifetime of the fixture -- not the setup order based on the parameters of your test, the first argument's fixture gets set up first in your case you have a few choices if you want to force the ordering -- one is to reorder the parameters of your test such that |
Documentation says that scope is about ordering. https://docs.pytest.org/en/stable/fixture.html#order-higher-scoped-fixtures-are-instantiated-first |
If we define
import pytest
@pytest.fixture(scope='module')
def customer2(customer):
return customer + 1
def test_1(module_transaction, customer2):
assert customer2 == 2 $ pytest tests --setup-only
Loading .env environment variables...
============================= test session starts ==============================
platform linux2 -- Python 2.7.15rc1, pytest-4.6.11, py-1.8.0, pluggy-0.13.0
rootdir: /home/voronin/projects/sintez_addons, inifile: setup.cfg
plugins: cov-2.10.0, flake8-1.0.4, forked-1.1.3, xdist-1.31.0
collected 1 item
tests/test_1.py
SETUP S customer
SETUP M module_transaction
SETUP M customer2 (fixtures used: customer)
test-module/test_1.py::test_1 (fixtures used: customer, customer2, module_transaction)
TEARDOWN M customer2
TEARDOWN M module_transaction
TEARDOWN S customer
========================= no tests ran in 0.02 seconds ========================= |
Hi @voronind, @asottile is correct, but your example is a bit different from the docs because your test is not requesting the
Currently we don't do a complete fixture resolution order before setting up things, but that's being discussed in #4871. Closing this for now. 👍 |
If we have session fixture
customer
and redefine it with module scope, It can run after module fixtures.tests/conftest.py
tests/test_1.py
The text was updated successfully, but these errors were encountered: