Skip to content

Conversation

@bluetech
Copy link
Member

@bluetech bluetech commented Mar 8, 2024

These are a few more cleanup commits to the fixtures code, in the continuing quest to bring out its inner beauty :)

bluetech added 4 commits March 9, 2024 00:02
There are two non-optimal things in the current way scope checking is
done:

- It runs on `SubRequest`, but doesn't use the `SubRequest's scope,
  which is confusing. Instead it takes `invoking_scope` and
  `requested_scope`.

- Because `_check_scope` is only defined on `SubRequest` and not
  `TopRequest`, `_compute_fixture_value` first creates the `SubRequest`
  only then checks the scope (hence the need for the previous point).

Instead, also define `_check_scope` on `TopRequest` (always valid), and
remove `invoking_scope`, using `self._scope` instead.
- Separate the requesting from the requested.

- Avoid the term "factory", I think most people don't distinguish
  between "fixture" and "fixture function" (i.e. "factory") and would
  find the term "factory" unfamiliar.
This makes sure the scope is always compatible, and also allows using
`getfixturevalue` in `pytest_fixture_setup` so less internal magic.
Copy link
Member

@nicoddemus nicoddemus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, nice cleanup!

@bluetech bluetech merged commit 437eb86 into pytest-dev:main Mar 9, 2024
@bluetech bluetech deleted the fixture-cleanup branch March 9, 2024 06:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants