question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

lazy-fixture-0.5.2: function fixture runs before module fixture

See original GitHub issue

pytest-5.1.3 lazy-fixture-0.5.2

Example:

import pytest
from pytest_lazyfixture import lazy_fixture

@pytest.fixture(scope="module")
def module_fixture():
    print('using module fixture')

@pytest.fixture
def fixture1():
    print("using fixture1")

@pytest.fixture
def fixture2():
    print("using fixture2")

@pytest.mark.usefixtures("module_fixture")
@pytest.mark.parametrize("fixt", [lazy_fixture("fixture1"), lazy_fixture("fixture2")])
def test_test(fixt):
    pass

output

smoke/test_test.py::test_test[fixt0] using fixture1
using module fixture
PASSED
smoke/test_test.py::test_test[fixt1] using fixture2
PASSED

There is strange order - fixture1, module fixture, fixture2

Same example without using lazy_fixture:

@pytest.mark.usefixtures("module_fixture")
def test_test1(fixture1):
    pass


@pytest.mark.usefixtures("module_fixture")
def test_test2(fixture2):
    pass

output:

smoke/test_test.py::test_test1 using module fixture
using fixture1
PASSED
smoke/test_test.py::test_test2 using fixture2
PASSED

Executing order looks as designed - module fixture, fixture1, fixture2

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:7
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
TvoroGcommented, Sep 25, 2019

Thanks, @lenvk! I’ll look at it.

0reactions
TvoroGcommented, Oct 15, 2019

Yep, it’s time)

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to use fixtures — pytest documentation
Once pytest finds them, it runs those fixtures, captures what they returned (if anything), and passes those objects into the test function as...
Read more >
setup_* executed before all fixtures · Issue #517 · pytest-dev ...
Another way to put it: Are there any reasons to not run fixtures before all ... in the same file/module as the test...
Read more >
How can i run the fixture before other fixtures? pytest python3.7
I want to run the fixture before other fixtures. How can I set one function to run before all the function in "conftest.py"?...
Read more >
pytest fixtures: explicit, modular, scalable
fixtures have explicit names and are activated by declaring their use from test functions, modules, classes or whole projects. fixtures are implemented in...
Read more >
pytest fixtures easy example | pythontest - Brian Okken
Module level fixtures don't work if you just want to run the one function that doesn't use the resource. I then presented class...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found