Skip to content

Conversation

@asnare
Copy link
Contributor

@asnare asnare commented Jul 14, 2025

Internally the unit tests for pytester access pytest fixtures directly. This has been deprecated since 4.x, but the project currently contains some workarounds (in call_fixture()) to do this anyway.

In pytest 8.4, the internals changed which breaks the way call_fixture() accesses the underlying fixture. This PR:

  • Updates call_fixture() minimally so that it also works with 8.4+.
  • Adds a marker that we should fix this properly.
  • Notes a promising direction for doing what we want in a supported manner.

Resolves #165.

The implementation retains compatibility with older versions.
@asnare asnare self-assigned this Jul 14, 2025
@asnare asnare requested a review from nfx as a code owner July 14, 2025 10:16
@asnare asnare added bug Something isn't working tech debt labels Jul 14, 2025
@asnare asnare requested review from gueniai and sundarshankar89 and removed request for nfx July 14, 2025 10:16
@asnare asnare temporarily deployed to account-admin July 14, 2025 10:19 — with GitHub Actions Inactive
@github-actions
Copy link

✅ 41/41 passed, 5 skipped, 6m45s total

Running from acceptance #207

@asnare asnare requested a review from pritishpai July 16, 2025 17:34
@asnare asnare merged commit a193944 into main Jul 16, 2025
9 of 10 checks passed
@asnare asnare deleted the fix/pytest-compatibility branch July 16, 2025 17:43
gueniai added a commit that referenced this pull request Aug 7, 2025
* Added property `id` to get service principal id ([#170](#170)). The service principal functionality has been enhanced with the introduction of a new `id` property, which returns the service principal ID as a string, simplifying its usage in tests. The `create` method has been updated to utilize this `id` property, ensuring consistency throughout the code. Additionally, the `id` property is now directly used when creating secrets, updating group memberships, and updating workspace assignments, with the exception of the `workspace_assignment.update` method. The logging of account links has also been updated to use the `id` property. Furthermore, test cases have been updated to include service principals in group members, and a new function `make_run_as` has been introduced to create service principals for testing purposes, along with a new test case `test_make_run_as_no_args` to verify its functionality, addressing issues related to no-cheat in linked pull requests and improving overall testing capabilities.
* Updated `call_fixture()` to work with pytest 8.4 ([#166](#166)). The `call_fixture` function has been enhanced to support pytest version 8.4 and later, while maintaining backward compatibility with older versions. To address the deprecation of direct access to pytest fixtures since version 4.x, the function now dynamically checks the pytest version and utilizes the corresponding mechanism to unwrap fixtures. For pytest 8.4 and later, it leverages the `_get_wrapped_function` attribute, whereas for older versions, it relies on the `__pytest_wrapped__` attribute. Additionally, the function now includes input validation, raising a `ValueError` if the provided function is not a valid pytest fixture, ensuring more robust error handling. This update provides a temporary solution, with plans for future refinement to potentially utilize `pytest.FixtureRequest` and `request.getfixturevalue()` for accessing fixtures in a more supported and sustainable manner.
@gueniai gueniai mentioned this pull request Aug 7, 2025
gueniai added a commit that referenced this pull request Aug 7, 2025
# Release notes:
* Added property `id` to get service principal id
([#170](#170)). The
service principal functionality has been enhanced with the introduction
of a new `id` property, which returns the service principal ID as a
string, simplifying its usage in tests. The `create` method has been
updated to utilize this `id` property, ensuring consistency throughout
the code. Additionally, the `id` property is now directly used when
creating secrets, updating group memberships, and updating workspace
assignments, with the exception of the `workspace_assignment.update`
method. The logging of account links has also been updated to use the
`id` property. Furthermore, test cases have been updated to include
service principals in group members, and a new function `make_run_as`
has been introduced to create service principals for testing purposes,
along with a new test case `test_make_run_as_no_args` to verify its
functionality, addressing issues related to no-cheat in linked pull
requests and improving overall testing capabilities.
* Updated `call_fixture()` to work with pytest 8.4
([#166](#166)). The
`call_fixture` function has been enhanced to support pytest version 8.4
and later, while maintaining backward compatibility with older versions.
To address the deprecation of direct access to pytest fixtures since
version 4.x, the function now dynamically checks the pytest version and
utilizes the corresponding mechanism to unwrap fixtures. For pytest 8.4
and later, it leverages the `_get_wrapped_function` attribute, whereas
for older versions, it relies on the `__pytest_wrapped__` attribute.
Additionally, the function now includes input validation, raising a
`ValueError` if the provided function is not a valid pytest fixture,
ensuring more robust error handling. This update provides a temporary
solution, with plans for future refinement to potentially utilize
`pytest.FixtureRequest` and `request.getfixturevalue()` for accessing
fixtures in a more supported and sustainable manner.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working tech debt

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Compatibility issues with pytest 8.4+

3 participants