Skip to content

Commit bd2fae3

Browse files
author
Sylvain MARIE
committed
pytest_parametrize_plus was not working correctly with test classes, leading to fixture 'self' not found. Fixed #63
1 parent 9c954e9 commit bd2fae3

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

pytest_cases/main_fixtures.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1134,7 +1134,8 @@ def parametrize_plus_decorate(test_func):
11341134
# it is the same than existing, except that we want to replace all parameters with the new fixture
11351135

11361136
new_sig = remove_signature_parameters(old_sig, *all_param_names)
1137-
new_sig = add_signature_parameters(new_sig, Parameter(base_name, kind=Parameter.POSITIONAL_OR_KEYWORD))
1137+
# add it in last position, so that potential 'self' argument (case of test class methods) can stay first
1138+
new_sig = add_signature_parameters(new_sig, last=Parameter(base_name, kind=Parameter.POSITIONAL_OR_KEYWORD))
11381139

11391140
# --Finally create the fixture function, a wrapper of user-provided fixture with the new signature
11401141
def replace_paramfixture_with_values(kwargs):
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# test.py
2+
import pytest
3+
from pytest_cases import fixture_ref, pytest_parametrize_plus
4+
5+
6+
@pytest.fixture
7+
def foo():
8+
return 1
9+
10+
11+
@pytest.fixture
12+
def bar():
13+
return 2
14+
15+
16+
@pytest_parametrize_plus("arg", [fixture_ref("foo"), fixture_ref("bar")])
17+
def test_thing(arg):
18+
print(arg)
19+
20+
21+
class TestCase:
22+
@pytest.mark.parametrize("arg", [1, 2])
23+
def test_thing_pytest(self, arg):
24+
print(arg)
25+
26+
@pytest_parametrize_plus("arg", [fixture_ref("foo"), fixture_ref("bar")])
27+
def test_thing_cases(self, arg):
28+
print(arg)

0 commit comments

Comments
 (0)