Skip to content

Commit f05748b

Browse files
author
Sylvain MARIE
committed
Added a test for workaround in issue #211 + minor docstring edit + changelog update
1 parent 14182ed commit f05748b

File tree

3 files changed

+43
-1
lines changed

3 files changed

+43
-1
lines changed

docs/changelog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
### (in progress) - `currentcases` fixture cleanup
4+
5+
- Fixed minor issue where empty entries could be present in `currentcases`. Fixes [#213](https://github.com/smarie/python-pytest-cases/issues/213)
6+
37
### 3.5.2 - bugfix with the `currentcases` fixture
48

59
- Fixed issues where the `currentcases` fixture would not return the correct case function. Fixed [#212](https://github.com/smarie/python-pytest-cases/issues/212)

pytest_cases/case_parametrizer_new.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ def case_to_argvalues(host_class_or_module, # type: Union[Type, ModuleType]
422422
# id="%s-%s" % (case_id, c.id), marks=case_marks + tuple(c.marks))
423423
# for c in meta._calls)
424424
else:
425-
# at least a required fixture (direct req or through @pytest.mark.usefixtures ):
425+
# at least 1 required fixture (direct req or through @pytest.mark.usefixtures ), OR parametrized.
426426

427427
# if meta.is_parametrized:
428428
# # nothing to do, the parametrization marks are on the fixture to create so they will be taken into account
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import pytest
2+
import sys
3+
from pytest_cases import parametrize, parametrize_with_cases
4+
5+
6+
PY3 = sys.version_info >= (3,)
7+
8+
9+
class MyClassName:
10+
@parametrize(name=("joe", "alice"))
11+
def case_widget(self, name):
12+
return name
13+
14+
def case_foo(self):
15+
return "foo"
16+
17+
18+
@parametrize_with_cases('val', cases=MyClassName)
19+
def test_function(val, current_cases, request):
20+
print(val)
21+
case_id, case_func = current_cases['val']
22+
print((case_id, case_func))
23+
24+
if (case_func is MyClassName.case_widget) if PY3 else (case_func == MyClassName.case_widget):
25+
# workaround to get the parameter, but a bit dirty
26+
if request.node.callspec.params['widget'].argvalues[0] == "joe":
27+
assert request.node.name == 'test_function[widget-name=joe]'
28+
pytest.skip("joe skipped")
29+
30+
assert request.node.name != 'test_function[widget-name=joe]'
31+
32+
33+
def test_synthesis(module_results_dct):
34+
assert list(module_results_dct) == [
35+
'test_function[widget-name=joe]',
36+
'test_function[widget-name=alice]',
37+
'test_function[foo]'
38+
]

0 commit comments

Comments
 (0)