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.

Move pytest fixtures to ``conftest.py``

See original GitHub issue

Description

Pytest fixtures are best defined in a conftest.py, in whatever subpackage the tests are for. This has a number of advantages, not least of which is avoiding the annoying way that pytest is not compliant with F401 issues (See #13853).

Additional context

https://docs.pytest.org/en/7.1.x/reference/fixtures.html#conftest-py-sharing-fixtures-across-multiple-files

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:1
  • Comments:12 (12 by maintainers)

github_iconTop GitHub Comments

1reaction
Cadaircommented, Dec 9, 2022

Pytest fixtures are best defined in a conftest.py

I disagree with this as a general policy. If a fixture is only used in a single test file, then I think it’s much easier to read if you don’t have to go and open a second file to find the fixture.

1reaction
saimncommented, Dec 9, 2022

Why was that done in a PR named “Pre commit flake8s” amongst hundred of lines changed ? (#13853)

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to modularize your py.test fixtures - GitHub Gist
You can simply create "local pytest plugins" which can be nothing more than Python files with fixtures, e.g.. tests/unit/conftest.py: pytest_plugins = [ "tests....
Read more >
pytest fixtures: explicit, modular, scalable
The conftest.py file serves as a means of providing fixtures for an entire directory. Fixtures defined in a conftest.py can be used by...
Read more >
In pytest, what is the use of conftest.py files? - Stack Overflow
Yes it is. Fixtures are a potential and common use of conftest.py . The fixtures that you will define will be shared among...
Read more >
Using Pytest Fixtures: A Step-by-Step Guide With Examples
In this step-by-step guide, we will go through a quick setup for Pytest with Fixtures and different types of fixtures.
Read more >
Pytest Tutorial: Sharing Fixtures Through conftest - YouTube
Pytest Tutorial: Sharing Fixtures Through conftest Pytest fixtures are one of the core features that make pytest framework stand out above ...
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