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.

pytest_generate_tests can't override fixture parameters?

See original GitHub issue

This 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:open
  • Created 3 years ago
  • Reactions:1
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
RonnyPfannschmidtcommented, Feb 15, 2021

I wonder if this is about the hook order

The Parametrize mark is implemented using that hook

0reactions
rjboczarcommented, Nov 11, 2022

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.

Read more comments on GitHub >

github_iconTop 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 >

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