@@ -2723,3 +2723,108 @@ def test_1(arg1):
27232723 *def arg1*
27242724 """ )
27252725
2726+ class TestParameterizedSubRequest :
2727+ def test_call_from_fixture (self , testdir ):
2728+ testfile = testdir .makepyfile ("""
2729+ import pytest
2730+
2731+ @pytest.fixture(params=[0, 1, 2])
2732+ def fix_with_param(request):
2733+ return request.param
2734+
2735+ @pytest.fixture
2736+ def get_named_fixture(request):
2737+ return request.getfuncargvalue('fix_with_param')
2738+
2739+ def test_foo(request, get_named_fixture):
2740+ pass
2741+ """ )
2742+ result = testdir .runpytest ()
2743+ result .stdout .fnmatch_lines ("""
2744+ E*Failed: The requested fixture has no parameter defined for the current test.
2745+ E*
2746+ E*Requested fixture 'fix_with_param' defined in:
2747+ E*{0}:4
2748+ E*Requested here:
2749+ E*{1}:9
2750+ *1 error*
2751+ """ .format (testfile .basename , testfile .basename ))
2752+
2753+ def test_call_from_test (self , testdir ):
2754+ testfile = testdir .makepyfile ("""
2755+ import pytest
2756+
2757+ @pytest.fixture(params=[0, 1, 2])
2758+ def fix_with_param(request):
2759+ return request.param
2760+
2761+ def test_foo(request):
2762+ request.getfuncargvalue('fix_with_param')
2763+ """ )
2764+ result = testdir .runpytest ()
2765+ result .stdout .fnmatch_lines ("""
2766+ E*Failed: The requested fixture has no parameter defined for the current test.
2767+ E*
2768+ E*Requested fixture 'fix_with_param' defined in:
2769+ E*{0}:4
2770+ E*Requested here:
2771+ E*{1}:8
2772+ *1 failed*
2773+ """ .format (testfile .basename , testfile .basename ))
2774+
2775+ def test_external_fixture (self , testdir ):
2776+ conffile = testdir .makeconftest ("""
2777+ import pytest
2778+
2779+ @pytest.fixture(params=[0, 1, 2])
2780+ def fix_with_param(request):
2781+ return request.param
2782+ """ )
2783+
2784+ testfile = testdir .makepyfile ("""
2785+ def test_foo(request):
2786+ request.getfuncargvalue('fix_with_param')
2787+ """ )
2788+ result = testdir .runpytest ()
2789+ result .stdout .fnmatch_lines ("""
2790+ E*Failed: The requested fixture has no parameter defined for the current test.
2791+ E*
2792+ E*Requested fixture 'fix_with_param' defined in:
2793+ E*{0}:4
2794+ E*Requested here:
2795+ E*{1}:2
2796+ *1 failed*
2797+ """ .format (conffile .basename , testfile .basename ))
2798+
2799+ def test_non_relative_path (self , testdir ):
2800+ tests_dir = testdir .mkdir ('tests' )
2801+ fixdir = testdir .mkdir ('fixtures' )
2802+ fixfile = fixdir .join ("fix.py" )
2803+ fixfile .write (_pytest ._code .Source ("""
2804+ import pytest
2805+
2806+ @pytest.fixture(params=[0, 1, 2])
2807+ def fix_with_param(request):
2808+ return request.param
2809+ """ ))
2810+
2811+ testfile = tests_dir .join ("test_foos.py" )
2812+ testfile .write (_pytest ._code .Source ("""
2813+ from fix import fix_with_param
2814+
2815+ def test_foo(request):
2816+ request.getfuncargvalue('fix_with_param')
2817+ """ ))
2818+
2819+ tests_dir .chdir ()
2820+ testdir .syspathinsert (fixdir )
2821+ result = testdir .runpytest ()
2822+ result .stdout .fnmatch_lines ("""
2823+ E*Failed: The requested fixture has no parameter defined for the current test.
2824+ E*
2825+ E*Requested fixture 'fix_with_param' defined in:
2826+ E*{0}:5
2827+ E*Requested here:
2828+ E*{1}:5
2829+ *1 failed*
2830+ """ .format (fixfile .strpath , testfile .basename ))
0 commit comments