Skip to content

Commit fb44fc3

Browse files
sliwinski-miloszyoutux
authored andcommitted
Fixes #273: Fix for unicode steps in gherkin reporter (#274)
* Fixes #273: Fix for unicode steps in gherkin reporter * Test unicode step names in gherkin expanded mode * Unnecessary encoding declaration in gherkin reporter test removed * Fix unicode steps by using unicode_literals in gherkin_terminal_reporter.py
1 parent 516533c commit fb44fc3

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

pytest_bdd/gherkin_terminal_reporter.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# -*- encoding: utf-8 -*-
22

3+
from __future__ import unicode_literals
4+
35
import re
46

57
from _pytest.terminal import TerminalReporter

tests/feature/test_gherkin_terminal_reporter.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import pytest
55

66
from pytest_bdd import scenario, given, when, then
7+
from tests.utils import get_test_filepath, prepare_feature_and_py_files
78

89

910
@scenario('gherkin_terminal_reporter.feature',
@@ -344,3 +345,22 @@ def output_output_must_contain_parameters_values(test_execution, gherkin_scenari
344345
ghe.stdout.fnmatch_lines('*When I eat {eat} cucumbers'.format(**gherkin_scenario_outline))
345346
ghe.stdout.fnmatch_lines('*Then I should have {left} cucumbers'.format(**gherkin_scenario_outline))
346347
ghe.stdout.fnmatch_lines('*PASSED')
348+
349+
350+
@pytest.mark.parametrize(
351+
'feature_file, py_file, name', [
352+
('./steps/unicode.feature', './steps/test_unicode.py', 'test_steps_in_feature_file_have_unicode')
353+
]
354+
)
355+
def test_scenario_in_expanded_mode(testdir, test_execution, feature_file, py_file, name):
356+
prepare_feature_and_py_files(testdir, feature_file, py_file)
357+
358+
test_execution['gherkin'] = testdir.runpytest(
359+
'-k %s' % name,
360+
'--gherkin-terminal-reporter',
361+
'--gherkin-terminal-reporter-expanded',
362+
'-vv',
363+
)
364+
365+
ghe = test_execution['gherkin']
366+
ghe.assert_outcomes(passed=1)

tests/utils.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import os
2+
3+
4+
def get_test_filepath(filepath):
5+
curr_file_dirpath = os.path.dirname(os.path.realpath(__file__))
6+
return os.path.join(curr_file_dirpath, filepath)
7+
8+
9+
def prepare_feature_and_py_files(testdir, feature_file, py_file):
10+
feature_filepath = get_test_filepath(feature_file)
11+
with open(feature_filepath) as feature_file:
12+
feature_content = feature_file.read()
13+
testdir.makefile('.feature', unicode=feature_content)
14+
15+
py_filepath = get_test_filepath(py_file)
16+
with open(py_filepath) as py_file:
17+
py_content = py_file.read()
18+
testdir.makepyfile(test_gherkin=py_content)

0 commit comments

Comments
 (0)