Skip to content

Commit 646fc1c

Browse files
Test parametrized tests in gherkin expanded mode
1 parent b3c0e3f commit 646fc1c

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

tests/feature/test_gherkin_terminal_reporter.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1+
import os
12
import re
23

3-
44
import pytest
55

6-
from pytest_bdd import scenario, given, when, then
6+
from pytest_bdd import given, scenario, then, when
77
from tests.utils import get_test_filepath, prepare_feature_and_py_files
88

99

@@ -349,18 +349,18 @@ def output_output_must_contain_parameters_values(test_execution, gherkin_scenari
349349

350350
@pytest.mark.parametrize(
351351
'feature_file, py_file, name', [
352-
('./steps/unicode.feature', './steps/test_unicode.py', 'test_steps_in_feature_file_have_unicode')
352+
('./steps/unicode.feature', './steps/test_unicode.py', 'test_steps_in_feature_file_have_unicode'),
353+
('./feature/parametrized.feature', './feature/test_parametrized.py', 'test_parametrized')
353354
]
354355
)
355-
def test_scenario_in_expanded_mode(testdir, test_execution, feature_file, py_file, name):
356+
def test_scenario_in_expanded_mode(testdir, feature_file, py_file, name):
356357
prepare_feature_and_py_files(testdir, feature_file, py_file)
357358

358-
test_execution['gherkin'] = testdir.runpytest(
359-
'-k %s' % name,
359+
py_filename = os.path.basename(py_file)
360+
result = testdir.runpytest(
361+
'%s::%s' % (py_filename, name),
360362
'--gherkin-terminal-reporter',
361363
'--gherkin-terminal-reporter-expanded',
362364
'-vv',
363365
)
364-
365-
ghe = test_execution['gherkin']
366-
ghe.assert_outcomes(passed=1)
366+
result.assert_outcomes(passed=1)

tests/utils.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,21 @@ def get_test_filepath(filepath):
55
curr_file_dirpath = os.path.dirname(os.path.realpath(__file__))
66
return os.path.join(curr_file_dirpath, filepath)
77

8+
def get_filename_without_ext(path):
9+
filename = os.path.basename(path)
10+
return os.path.splitext(filename)[0]
811

912
def prepare_feature_and_py_files(testdir, feature_file, py_file):
1013
feature_filepath = get_test_filepath(feature_file)
1114
with open(feature_filepath) as feature_file:
1215
feature_content = feature_file.read()
13-
testdir.makefile('.feature', unicode=feature_content)
16+
feature_filename = get_filename_without_ext(feature_file.name)
17+
kwargs = {feature_filename: feature_content}
18+
testdir.makefile('.feature', **kwargs)
1419

1520
py_filepath = get_test_filepath(py_file)
1621
with open(py_filepath) as py_file:
1722
py_content = py_file.read()
18-
testdir.makepyfile(test_gherkin=py_content)
23+
py_filename = get_filename_without_ext(py_file.name)
24+
kwargs = {py_filename: py_content}
25+
testdir.makepyfile(**kwargs)

0 commit comments

Comments
 (0)