Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix _after_postgeneration being invoked twice #164

Merged
merged 9 commits into from
Jun 5, 2022

Conversation

youtux
Copy link
Contributor

@youtux youtux commented Jun 4, 2022

Partially fixes #156.

@youtux youtux marked this pull request as ready for review June 4, 2022 10:40
@youtux youtux merged commit 12a91d4 into master Jun 5, 2022
@youtux youtux deleted the fix-after-postgeneration branch June 5, 2022 16:39
"""Get the local namespace of the caller frame."""
return sys._getframe(depth).f_locals
return sys._getframe(depth + 2).f_locals
Copy link
Contributor

Choose a reason for hiding this comment

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

why this change is required?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

not needed, but it makes more sense, so that the caller can specify if it wants the locals from the caller (from its POV) or levels from its POV

@@ -291,6 +291,24 @@ def evaluate(request: SubRequest, value: LazyFixture[T] | T) -> T:
return value.evaluate(request) if isinstance(value, LazyFixture) else value


def noop(*args: Any, **kwargs: Any) -> None:
"""No-op function."""
pass
Copy link
Contributor

Choose a reason for hiding this comment

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

NIP: pass is not required when docstring is provided

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah yeah true that


def test_postgeneration_called_once(self, request):
"""Test that ``_after_postgeneration`` is called only once."""
foo = request.getfixturevalue("collector")
Copy link
Contributor

Choose a reason for hiding this comment

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

why not add collector as a test's function argument to let pytest do the job of getting the fixture value?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it's just in case there is an error in the setup, it's nicer to have the tests error out at runtime, rather than at collection time (especially if doing TDD), as it would prevent you from running other tests

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.

pytest-factoryboy seems to break factory.django.mute_signals
2 participants