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
ScopeMismatch with parametrized cases #311
Comments
Sorry, this seems a bit more complicated than just passing on scope as I suggested above. It appears to be an issue of name conflict for case-parametrized fixtures that are defined within conftest.py. The name-conflict resolution here python-pytest-cases/src/pytest_cases/case_parametrizer_new.py Lines 533 to 565 in ab3b719
does not actually fix the conflict because
A solution would be to prepend "conftest_" to the
with all the modules identical to my previous example but, test_deeper/conftest.py from pytest_cases import fixture, parametrize_with_cases
@fixture(scope='class')
@parametrize_with_cases('arg', cases='cases', scope='class')
def scope_mismatch_deeper(arg):
return arg While scope_mismatch_deeper is being parametrized, The ideal solution would be to have a |
Sorry for the spam. Perhaps a simpler solution than a E.g., if target_host.__name__ == 'conftest':
case_id = 'conftest_' + case_id + '_with_scope_' + scope This has the disadvantage of making names longer. If this sounds acceptable, I can also include it in the PR. |
Thanks @michele-riva for reporting this issue and working on a solution ! This is definitely one of the nasty aspects of pytest-cases: it generates a lot of fixtures behind the scenes. Does your issue also happen when the cases are in the same file than the test file, and cases are just imported with |
No worries, I'm also pretty toasted. I have some code in a fork, and I'll prepare a PR today.
Good question. I'd have to try it out. I'll update the tests if this is the case. |
Looks like the issue does not show up for cases defined in the same file. I'll have to go for the more complicated structure. |
I've just opened #317, which should fix this. Happy to discuss edits if needed. |
Ok, thanks for checking! This might explain why this issue has not been reported yet. |
* tests: add test for issue #311 * fix: propagate scope in ...ParamAlternative * fix: mangle fixture name for conftest 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. * fix: avoid conflict also if __init__.py exists 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. * Do not pass on None as scope 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. * More explicit None scope replacement As suggested by @smarie * Add note and example for conftest qualname * Test correctness of scopes As suggested by @smarie * Add changelog for #317 * Update docs/changelog.md --------- Co-authored-by: Sylvain Marié <sylvain.marie@schneider-electric.com>
Hi, here's the last one. A bit hairier.
Example to reproduce:
cases.py
conftest.py
test_scope_mismatch.py
Gives:
Notice that this does not happen if the two fixtures are defined in the same module (either
conftest.py
ortest_scope_mismatch.py
). Also, this may be obscured by #309 or #310 if using AUTO cases.It looks like the core of the issue is that the scope keyword argument is not passed to the .create calls here
python-pytest-cases/src/pytest_cases/fixture_parametrize_plus.py
Lines 847 to 872 in ab3b719
In principle I can draft a PR.
The text was updated successfully, but these errors were encountered: