-
-
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
fixture scope is ignored when using metafunc.parametrize() #519
Comments
I have a test suite where I have to run some very expensive configuration before running all the tests, and the set of possible configurations is the Cartesian product of modes that are fixed with versions that I need to be able to pass in at run-time. I'm currently using a session-scoped fixture that's parametrized only by the modes, and I need to extend it to be parametrized by the versions too. The only way I've found to do parametrization of a fixture dependent on command-line arguments is pytest_generate_tests, but this bug breaks it for session fixtures. Thus, I see three possible routes:
|
@ceridwen I think the proper way to define fixtures dynamically based on command-line variables is demonstrated in #2959 (comment). Does that solve it for you? |
Unfortunately, not quite, see #3161. I'm starting to suspect there's a more fundamental bug lurking here. |
add example scripts for issue #519
Note that the output changed with 9e26203, so the test should likely be fixed. Ref: pytest-dev#519 (- haven't looked into what the issue is about). Example script was added in c081c5e, changed in ea90605, currently outputs: Previous output: ``` ['============================= test session starts ==============================', 'platform linux -- Python 3.8.1, pytest-5.3.5.dev567+gfba7d992a.d20200224, py-1.8.2.dev3+g2b6bd292, pluggy-0.13.1', 'rootdir: ~', 'collected 8 items', '', 'issue_519.py ........E [100%]', '', '==================================== ERRORS ====================================', '_________________ ERROR at teardown of test_two[arg1v2-arg2v2] _________________', '', ' @pytest.fixture(scope="session")', ' def checked_order():', ' order = []', ' ', ' yield order', ' pprint.pprint(order)', '> assert order == [', ' ("testing/example_scripts/issue_519.py", "fix1", "arg1v1"),', ' ("test_one[arg1v1-arg2v1]", "fix2", "arg2v1"),', ' ("test_two[arg1v1-arg2v1]", "fix2", "arg2v1"),', ' ("test_one[arg1v1-arg2v2]", "fix2", "arg2v2"),', ' ("test_two[arg1v1-arg2v2]", "fix2", "arg2v2"),', ' ("testing/example_scripts/issue_519.py", "fix1", "arg1v2"),', ' ("test_one[arg1v2-arg2v1]", "fix2", "arg2v1"),', ' ("test_two[arg1v2-arg2v1]", "fix2", "arg2v1"),', ' ("test_one[arg1v2-arg2v2]", "fix2", "arg2v2"),', ' ("test_two[arg1v2-arg2v2]", "fix2", "arg2v2"),', ' ]', "E AssertionError: assert [('issue_519....arg1v2'), ...] == [('testing/ex...arg1v2'), ...]", 'E At index 0 diff:', "E ('issue_519.py', 'fix1', 'arg1v1') !=", "E ('testing/example_scripts/issue_519.py', 'fix1', 'arg1v1')", 'E Use -v to get the full diff', '', "issue_519.py:20: AssertionError: assert [('issue_519....arg1v2'), ...] == [('testing/ex...arg1v2'), ...]...", '--------------------------- Captured stdout teardown ---------------------------', "[('issue_519.py', 'fix1', 'arg1v1'),", " ('test_one[arg1v1-arg2v1]', 'fix2', 'arg2v1'),", " ('test_two[arg1v1-arg2v1]', 'fix2', 'arg2v1'),", " ('test_one[arg1v1-arg2v2]', 'fix2', 'arg2v2'),", " ('test_two[arg1v1-arg2v2]', 'fix2', 'arg2v2'),", " ('issue_519.py', 'fix1', 'arg1v2'),", " ('test_one[arg1v2-arg2v1]', 'fix2', 'arg2v1'),", " ('test_two[arg1v2-arg2v1]', 'fix2', 'arg2v1'),", " ('test_one[arg1v2-arg2v2]', 'fix2', 'arg2v2'),", " ('test_two[arg1v2-arg2v2]', 'fix2', 'arg2v2')]", ```
i believe #11220 fixed this one |
Thanks @RonnyPfannschmidt, let's close this then, and reopen if we find it was not the case. 👍 |
Originally reported by: Nikolaus Rath (BitBucket: nikratio, GitHub: nikratio)
Please take a look at the following example:
As I understand,
test_one
andtest_two
should be executed 4 times each. Thefix2
function should be called once for every test execution (because it has function scope), and thefix1
function once for every value ofarg1
(because it has module scope).However, in practice
fix1
seems to be called for every test function as well, as if it had function scope:Looks like a bug to me.
The text was updated successfully, but these errors were encountered: