Document selecting loop factories per test#1432
Document selecting loop factories per test#1432tjkuson wants to merge 3 commits intopytest-dev:mainfrom
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1432 +/- ##
=======================================
Coverage 94.50% 94.50%
=======================================
Files 2 2
Lines 510 510
Branches 62 62
=======================================
Hits 482 482
Misses 22 22
Partials 6 6 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
| The hook receives the test item, so it can choose which factories are available for that test. | ||
| For example, it can inspect markers, fixture names, or the test node ID: | ||
|
|
||
| .. code-block:: python |
There was a problem hiding this comment.
The pytest-asyncio test suite discovers tests in Python files under the docs directory. This allows executing the code examples in the documentation and make it less likely for them to be outdated or break. This is currently done via an include directive, such as in parametrize_with_asyncio.{rst.py}.
Would it be possible to use the same approach for these two code examples? I imagine it would just work when grouping both of them into a subfolder under how-to-guides/.
If it doesn't work straight away, we leave it as is.
There was a problem hiding this comment.
The first part up to line 18 explains that all tests are parametrized with whatever entries are returned by the hook and that users can limit the parametrization via the loop_factories argument in the asyncio marker. The added code examples show an "inverted" control flow: there's no parametrization by default, unless the user explicitly lists the factory identifier in loop_factories.
I understand that we want to show both and each content makes sense, but it could be confusing that two approaches are mixed.
I'm not sure how to best solve this. We could either highlight that these are two very different approaches, e.g. "Variant 1, Variant 2" headlines or keep both variants in separate how-tos. I'm leaning towards the latter, but I'm failing to come up with distinguishable how-to titles.
There was a problem hiding this comment.
Yeah, I see what you mean.
I revisited how Diátaxis works and I think there's a reasonable argument in favour of this being three separate how-to guides: how to declare the event loop factories; how to declare factories based on item-specific logic; and how to select a subset of available factories from a test. I am curious what you think: 0a1803d f1a4d0d
Document in more detail how to select loop factories per test (specifically, how the hook interacts with the
loop_factoriesparameter).The gist of what this is trying to do is document how
loop_factoriesworks alongside pytest's ordinary hook semantics.Relates to #1101 (comment)
CI is failing as I didn't update the changelog. My understanding is that this PR can skip the changelog as the documentation hasn't been released yet.