Skip to content

Commit

Permalink
Test parametrized tests in gherkin expanded mode
Browse files Browse the repository at this point in the history
  • Loading branch information
sliwinski-milosz committed Dec 19, 2018
1 parent b3c0e3f commit 646fc1c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
18 changes: 9 additions & 9 deletions tests/feature/test_gherkin_terminal_reporter.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import os
import re


import pytest

from pytest_bdd import scenario, given, when, then
from pytest_bdd import given, scenario, then, when
from tests.utils import get_test_filepath, prepare_feature_and_py_files


Expand Down Expand Up @@ -349,18 +349,18 @@ def output_output_must_contain_parameters_values(test_execution, gherkin_scenari

@pytest.mark.parametrize(
'feature_file, py_file, name', [
('./steps/unicode.feature', './steps/test_unicode.py', 'test_steps_in_feature_file_have_unicode')
('./steps/unicode.feature', './steps/test_unicode.py', 'test_steps_in_feature_file_have_unicode'),
('./feature/parametrized.feature', './feature/test_parametrized.py', 'test_parametrized')
]
)
def test_scenario_in_expanded_mode(testdir, test_execution, feature_file, py_file, name):
def test_scenario_in_expanded_mode(testdir, feature_file, py_file, name):
prepare_feature_and_py_files(testdir, feature_file, py_file)

test_execution['gherkin'] = testdir.runpytest(
'-k %s' % name,
py_filename = os.path.basename(py_file)
result = testdir.runpytest(
'%s::%s' % (py_filename, name),
'--gherkin-terminal-reporter',
'--gherkin-terminal-reporter-expanded',
'-vv',
)

ghe = test_execution['gherkin']
ghe.assert_outcomes(passed=1)
result.assert_outcomes(passed=1)
11 changes: 9 additions & 2 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,21 @@ def get_test_filepath(filepath):
curr_file_dirpath = os.path.dirname(os.path.realpath(__file__))
return os.path.join(curr_file_dirpath, filepath)

def get_filename_without_ext(path):
filename = os.path.basename(path)
return os.path.splitext(filename)[0]

def prepare_feature_and_py_files(testdir, feature_file, py_file):
feature_filepath = get_test_filepath(feature_file)
with open(feature_filepath) as feature_file:
feature_content = feature_file.read()
testdir.makefile('.feature', unicode=feature_content)
feature_filename = get_filename_without_ext(feature_file.name)
kwargs = {feature_filename: feature_content}
testdir.makefile('.feature', **kwargs)

py_filepath = get_test_filepath(py_file)
with open(py_filepath) as py_file:
py_content = py_file.read()
testdir.makepyfile(test_gherkin=py_content)
py_filename = get_filename_without_ext(py_file.name)
kwargs = {py_filename: py_content}
testdir.makepyfile(**kwargs)

0 comments on commit 646fc1c

Please sign in to comment.