pytest_generate_tests can't override fixture parameters?
See original GitHub issueThis is supposed to work right?
import pytest
@pytest.fixture(params=[10,20])
def foo(request):
return request.param
def test_foo(foo):
assert foo % 10 == 0
def pytest_generate_tests(metafunc):
metafunc.parametrize('foo', [100,200,300])
What I get is:
e/lib/python3.8/site-packages/_pytest/fixtures.py:1581: in pytest_generate_tests
metafunc.parametrize(
e/lib/python3.8/site-packages/_pytest/python.py:1100: in parametrize
newcallspec.setmulti2(
e/lib/python3.8/site-packages/_pytest/python.py:932: in setmulti2
self._checkargnotcontained(arg)
e/lib/python3.8/site-packages/_pytest/python.py:909: in _checkargnotcontained
raise ValueError(f"duplicate {arg!r}")
E ValueError: duplicate 'foo'
environment:
(e) dispater.local:~/Desktop$ pip list
Package Version
---------- -------
attrs 20.3.0
iniconfig 1.1.1
packaging 20.9
pip 20.3.3
pluggy 0.13.1
py 1.10.0
pyparsing 2.4.7
pytest 6.2.2
setuptools 51.1.0
toml 0.10.2
wheel 0.36.2
WARNING: You are using pip version 20.3.3; however, version 21.0.1 is available.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:6 (3 by maintainers)
Top Results From Across the Web
pytest user override of parametrized fixture - Stack Overflow
For non-parametrized fixtures, I override fixture return values via pytest hook def pytest_generate_tests(self, metafunc): for fixture_name, ...
Read more >Deep dive into Pytest parametrization | by George Shuklin
Fixture parameters and pytest_generate_tests. Pytest is an amazing testing framework for Python. In this article I will focus on how fixture parametrization ...
Read more >Parametrizing tests — pytest documentation
Let's say we want to execute a test with different computation parameters and the parameter range shall be determined by a command line...
Read more >Function-level fixture parametrization (or, some pytest magic)
Fixtures are a wonderful bit of magic for performing test setup and dependency ... There's an undefined parameter or fixture: ksize .
Read more >pytest Documentation - Read the Docs
pytest provides Builtin fixtures/function arguments to request arbitrary resources, ... Override a fixture with direct test parametrization.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I wonder if this is about the hook order
The Parametrize mark is implemented using that hook
Gotcha; I tried this out to force a specific fixture to always be
indirect = True
in parametrize calls. It worked, but I bet with a more complicated setup something would break. I poked through the code a bit and there were definitely some scoping things you’d also have to fix manually.