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 3.3.0 immutable fixture params

See original GitHub issue

Before v3.3.0 it was possible to mutate fixture parameters, since v3.3.0 params gets “frozen” (I guess its introduced with this commit 07b2b18a01a3ba12757a4eb1c0e082922f5299e5)

I was using this feature to setup fixture parameters based on command-line options:

BINS = []

@pytest.fixture(scope='session', params=BINS, ids=...)
def server_bin(request):
    return request.param

@pytest.fixture(scope='session')
def run_server(server_bin):
    pass # start application

def pytest_configure(config):
    BINS[:] = config.getoption('--server')[:]

So my questions:

  • Is this new behavior intended or its a bug?
  • And if its intended what is new way to make dynamic parameters?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
nicoddemuscommented, Nov 29, 2017

@argaen and @popravich agree, thanks for the suggestion: #2980

0reactions
popravichcommented, Nov 29, 2017

@nicoddemus, the suggested code works with a tiny fix

def pytest_configure(config):
  class DynamicFixturePlugin(object):
     @pytest.fixture(scope='session', params=config.getoption('--servers'), ids=...)
-     def server_bin(request):
+     def server_bin(self, request):
        return request.param
    config.pluginmanager.register(DynamicFixturePlugin(), 'server-bin-fixture')

And I’m +1 to @argaen about some notes in CHANGELOG.

Read more comments on GitHub >

github_iconTop Results From Across the Web

pytest fixtures: explicit, modular, scalable
fixture management scales from simple unit to complex functional testing, allowing to parametrize fixtures and tests according to configuration and component ...
Read more >
pytest: Versions - Openbase
Full version history for pytest including change logs. ... #9514: Type-annotate FixtureRequest.param as Any as a stop gap measure until 8073 ...
Read more >
All You Need To Know To Start Using Fixtures In Your Pytest ...
The @pytest.fixture decorator provides an easy yet powerful way to setup and teardown resources. You can then pass these defined fixture objects ...
Read more >
Welcome to Pytest-BDD's documentation! — Pytest-BDD 6.1.1 ...
Step parsed arguments conflicted with the fixtures. Now they no longer define fixture. If the fixture has to be defined by the step...
Read more >
How To Make Your Pytest Tests as DRY as Bone
Furthermore, I have added the params argument to the fixture decorator. With this, you can define default values for your parameterized fixture.
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