February 2022
Intermediate to advanced
274 pages
6h 28m
English
You can put fixtures into individual test files, but to share fixtures among multiple test files, you need to use a conftest.py file either in the same directory as the test file that’s using it or in some parent directory. The conftest.py file is also optional. It is considered by pytest as a “local plugin” and can contain hook functions and fixtures.
Let’s start by moving the cards_db fixture out of test_count.py and into a conftest.py file in the same directory:
| | from pathlib import Path |
| | from tempfile import TemporaryDirectory |
| | import cards |
| | import pytest |
| | |
| | |
| | @pytest.fixture(scope="session") |
| | def cards_db(): |
| | """CardsDB object connected to a temporary database""" ... |
Read now
Unlock full access