Skip to content

Commit 792d0d2

Browse files
committed
Update fixture description docstrings
1 parent 293b1af commit 792d0d2

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

src/pytest_scenario_files/plugin.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class BadTestCaseDataException(Exception):
2222

2323
def pytest_addoption(parser, pluginmanager):
2424
"""
25-
Pytest hook function.
25+
Pytest hook function that adds the command line options.
2626
2727
Adds the command line option to automatically load responses and the
2828
additional option whether to require all responses to be fired.
@@ -246,19 +246,18 @@ def _extract_fixture_data(fixture_raw_data_dict: dict[str, dict[str, Any]]) -> t
246246

247247
@pytest.fixture(scope="function")
248248
def psf_responses(request: pytest.FixtureRequest) -> Generator[Response, None, None]:
249-
"""Load fixture data into responses mock.
249+
"""Returns a ResponsesMock with scenario data loaded.
250250
251-
Each test scenario needs to have its own responses mock, as they will be testing
252-
different aspects. We need to define a pytest fixture here and provide it to
253-
any scenario that uses responses.
251+
Used for integration with the Responses package. Each test scenario will get its
252+
own active ResponsesMock object. This object can then be updated at runtime
253+
to override the responses loaded from files.
254254
"""
255255
# Ultimately we need to wrap this up so that responses and httpx-responses
256256
# are both supported.
257-
# No qa flag as Ruff doesn't recognize the conditional import in pytest_configure()
258257
import responses
259258

260259
psf_fire_all_responses = request.config.getoption("psf-fire-all-responses")
261-
with responses.RequestsMock(assert_all_requests_are_fired=psf_fire_all_responses) as rsps: # noqa F821
260+
with responses.RequestsMock(assert_all_requests_are_fired=psf_fire_all_responses) as rsps:
262261
for one_response in request.param:
263262
rsps.add(**one_response)
264263
yield rsps
@@ -345,11 +344,17 @@ def _extract_responses(fixture_data_dict: dict[str, dict[str, Any]]) -> None:
345344

346345

347346
def pytest_generate_tests(metafunc: pytest.Metafunc) -> None:
348-
"""Pytest hook function called for each test.
347+
"""Pytest hook function that does the parameterization.
349348
350-
This is where the heavy lifting is done. This walks the directory tree
351-
looking for files that match the name of the test. Any data are loaded
352-
and used to parameterize the test for scenarios.
349+
This is where the heavy lifting is done. The process is:
350+
351+
1. Walk the directory tree looking for files that match the name of the test.
352+
2. Load test data from the files.
353+
3. Extract fixture names and check for consistency.
354+
4. Pull out indirect fixtures and remove suffixes from fixture names. (Includes
355+
handling the Responses integration.)
356+
5. Reformat the data for the parameterization.
357+
6. Make the function call.
353358
354359
:param metafunc: Pytest fixture used to create the parameterization
355360
"""

0 commit comments

Comments
 (0)