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 ScopeMismatch with parametrized cases #317

Merged
merged 11 commits into from
Nov 10, 2023

Conversation

michele-riva
Copy link
Contributor

@michele-riva michele-riva commented Oct 12, 2023

This PR fixes #311.
Tests that show the problem are also included.

Fixtures that are to be injected in conftest.py will be available globally. If we do not include this information in the name of the autogenerated fixtures, we may risk causing a conflict if another test/case/conftest uses parametrization on the same tests.
When conftest is in a package rather than in a mere folder, its name is "fully qualified".

Perhaps there would be no need to actually add the scope in this case, but better safe than sorry.
@michele-riva
Copy link
Contributor Author

@smarie, any chance to get the workflow above approved? This way I can officially make sure there are no conflicts

@smarie
Copy link
Owner

smarie commented Nov 8, 2023

Sorry @michele-riva , I am so late on my GH duties. Approved and unfortunately... failing :(

@michele-riva
Copy link
Contributor Author

Thanks, I am having a look at it. Seems I overlooked the default for the scope kwarg.

Make sure that the default scope always is "function" so as to avoid issues with pytest <= 6, which 'translates' the scope string kwarg into an index from a list. The list does not contain None.
@michele-riva
Copy link
Contributor Author

I think I have a fix. Would you mind approving the workflow once again?

@smarie
Copy link
Owner

smarie commented Nov 9, 2023

I think I have a fix. Would you mind approving the workflow once again?

sure. Sorry for this default github behaviour, if I remember correctly once you'll have contributed once then I will not have to approve anymore

@michele-riva
Copy link
Contributor Author

No worries! Thanks for the quick reply

@michele-riva
Copy link
Contributor Author

Great, looks like that did the trick. Feel free to suggest any change if you don't like the solutions.


@fixture
@parametrize_with_cases('arg', cases='cases')
def function_scoped(arg):
Copy link
Owner

Choose a reason for hiding this comment

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

Same comment as for the class-scoped: could you imagine a way to include this fixture in the test too, and in particular a way to be sure that the scope is correctly taken into account for all 3 ?


@fixture(scope='class')
@parametrize_with_cases('arg', cases='cases', scope='class')
def class_scoped(arg):
Copy link
Owner

Choose a reason for hiding this comment

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

This fixture does not appear to be used in the test. To be sure that the test works (and not only the pytest initial collection/setup), I would recommend to use this fixture somewhere in the test. In particular, the test does not at all validate that the scope is actually used.

This might require to create a second test, and to wrap both in a class..

@smarie
Copy link
Owner

smarie commented Nov 9, 2023

Overall great contribution @michele-riva , thanks ! In particular kudos for being able to walk your way through the horrible convoluted code of fixture parametrization :D

In addition to the comments above, could you please include a changlog entry for your contribution ?
Thanks !

@michele-riva
Copy link
Contributor Author

Overall great contribution @michele-riva , thanks ! In particular kudos for being able to walk your way through the horrible convoluted code of fixture parametrization :D

In addition to the comments above, could you please include a changlog entry for your contribution ? Thanks !

Sure! Will check back in when I have done all of these

@michele-riva
Copy link
Contributor Author

I have just modified the tests as per your suggestion. The check is somewhat indirect, though. I considered using a request for checking the scopes explicitly, but that was a bit cumbersome. Let me know if you feel like it'd be better to (also?) check explicitly the scope of the FixtureDefs

@michele-riva
Copy link
Contributor Author

Just updated the changelog in 02484e8.

From my perspective all is good to go. @smarie, let me know if there's anything else that you'd like changed. See also my #317 (comment)

@smarie smarie merged commit ac7f3c3 into smarie:main Nov 10, 2023
@smarie
Copy link
Owner

smarie commented Nov 10, 2023

All good thanks @michele-riva !

@michele-riva
Copy link
Contributor Author

Wonderful, thanks for checking!

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.

ScopeMismatch with parametrized cases
2 participants