FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Fix ScopeMismatch with parametrized cases by michele-riva · Pull Request #317 · smarie/python-pytest-cases · GitHub

Fix ScopeMismatch with parametrized cases - #317

Merged
smarie merged 11 commits into
smarie:mainfrom
michele-riva:fix_issue_311
Nov 10, 2023
Merged

Fix ScopeMismatch with parametrized cases#317
smarie merged 11 commits into
smarie:mainfrom
michele-riva:fix_issue_311

Conversation

michele-riva commented Oct 12, 2023
edited by smarie
Loading

Copy link
Copy Markdown
Contributor

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.

Copy link
Copy Markdown
Contributor Author

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

smarie commented Nov 8, 2023

Copy link
Copy Markdown
Owner

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

Copy link
Copy Markdown
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.

Copy link
Copy Markdown
Contributor Author

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

smarie commented Nov 9, 2023

Copy link
Copy Markdown
Owner

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

Copy link
Copy Markdown
Contributor Author

No worries! Thanks for the quick reply

Copy link
Copy Markdown
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
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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 commented Nov 9, 2023

Copy link
Copy Markdown
Owner

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 !

Copy link
Copy Markdown
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

Copy link
Copy Markdown
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

Copy link
Copy Markdown
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)

Comment thread docs/changelog.md
smarie merged commit ac7f3c3 into smarie:main Nov 10, 2023

smarie commented Nov 10, 2023

Copy link
Copy Markdown
Owner

All good thanks @michele-riva !

Copy link
Copy Markdown
Contributor Author

Wonderful, thanks for checking!

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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


Back | FazBrowse Home | New Git URL