-
Notifications
You must be signed in to change notification settings - Fork 41
Fix ScopeMismatch with parametrized cases #317
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
Changes from all commits
b6d1adb
3975f3c
5a06118
0d76061
c5432af
02484e8
484743a
2835d3c
8487bba
b8b3209
9ed516d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| from pytest_cases import parametrize | ||
|
|
||
|
|
||
| @parametrize(arg=(1,)) | ||
| def case_parametrized(arg): | ||
| return arg |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| from pytest_cases import fixture, parametrize_with_cases | ||
|
|
||
|
|
||
| @fixture(scope='session') | ||
| @parametrize_with_cases('arg', cases='cases', scope='session') | ||
| def scope_mismatch(arg): | ||
| return [arg] | ||
|
|
||
| session_scoped = scope_mismatch |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| from pytest_cases import fixture, parametrize_with_cases | ||
|
|
||
|
|
||
| @fixture(scope='class') | ||
| @parametrize_with_cases('arg', cases='cases', scope='class') | ||
| def class_scoped(arg): | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.. |
||
| return [arg] | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| from pytest_cases import fixture, parametrize_with_cases | ||
|
|
||
|
|
||
| @fixture | ||
| @parametrize_with_cases('arg', cases='cases') | ||
| def function_scoped(arg): | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 ? |
||
| return [arg] | ||
|
|
||
| # This tests would fail with a ScopeMismatch | ||
| # during collection before #317 | ||
| def test_scope_mismatch_collection(scope_mismatch): | ||
| assert scope_mismatch == [1] | ||
|
|
||
| def test_scopes(session_scoped, function_scoped, class_scoped): | ||
| session_scoped.append(2) | ||
| function_scoped.append(2) | ||
| class_scoped.append(2) | ||
| assert session_scoped == [1, 2] | ||
| assert function_scoped == [1, 2] | ||
| assert class_scoped == [1, 2] | ||
|
|
||
| def test_scopes_again(session_scoped, function_scoped, class_scoped): | ||
| session_scoped.append(3) | ||
| function_scoped.append(3) | ||
| class_scoped.append(3) | ||
| assert session_scoped == [1, 2, 3] | ||
| assert function_scoped == [1, 3] | ||
| assert class_scoped == [1, 3] | ||
|
|
||
|
|
||
| class TestScopesInClass: | ||
|
|
||
| def test_scopes_in_class(self, session_scoped, | ||
| function_scoped, class_scoped): | ||
| session_scoped.append(4) | ||
| function_scoped.append(4) | ||
| class_scoped.append(4) | ||
| assert session_scoped == [1, 2, 3, 4] | ||
| assert function_scoped == [1, 4] | ||
| assert class_scoped == [1, 4] | ||
|
|
||
| def test_scopes_in_class_again(self, session_scoped, | ||
| function_scoped, class_scoped): | ||
| session_scoped.append(5) | ||
| function_scoped.append(5) | ||
| class_scoped.append(5) | ||
| assert session_scoped == [1, 2, 3, 4, 5] | ||
| assert function_scoped == [1, 5] | ||
| assert class_scoped == [1, 4, 5] | ||
Uh oh!
There was an error while loading. Please reload this page.