From 24684bfb823f0a21ac5a52f294153016f2dfa7cf Mon Sep 17 00:00:00 2001 From: Anatoly Bubenkov Date: Thu, 4 Jun 2015 10:28:48 +0200 Subject: [PATCH] Fixed FeatureError string representation to correctly support python3. closes #115 --- AUTHORS.rst | 1 + CHANGES.rst | 5 +++++ pytest_bdd/feature.py | 6 +++--- tests/feature/test_scenario.py | 11 +++++++---- 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/AUTHORS.rst b/AUTHORS.rst index f3c3d37..5ca2aa7 100644 --- a/AUTHORS.rst +++ b/AUTHORS.rst @@ -14,5 +14,6 @@ These people have contributed to `pytest-bdd`, in alphabetical order: * `Dmitrijs Milajevs `_ * `Floris Bruynooghe `_ * `Harro van der Klauw `_ +* `Laurence Rowe `_ * `Leonardo Santagada `_ * `Robin Pedersen `_ diff --git a/CHANGES.rst b/CHANGES.rst index a71da0c..ad901c5 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,6 +1,11 @@ Changelog ========= +2.9.1 +----- + +- Fixed FeatureError string representation to correctly support python3 (bubenkoff, lrowe) + 2.9.0 ----- diff --git a/pytest_bdd/feature.py b/pytest_bdd/feature.py index 5f57c87..a26e91d 100644 --- a/pytest_bdd/feature.py +++ b/pytest_bdd/feature.py @@ -30,11 +30,13 @@ import sys import textwrap import glob2 +import six from . import types from . import exceptions +@six.python_2_unicode_compatible class FeatureError(Exception): """Feature parse error.""" @@ -42,9 +44,7 @@ class FeatureError(Exception): message = u"{0}.\nLine number: {1}.\nLine: {2}.\nFile: {3}" def __str__(self): - return unicode(self).encode("utf-8") - - def __unicode__(self): + """String representation.""" return self.message.format(*self.args) diff --git a/tests/feature/test_scenario.py b/tests/feature/test_scenario.py index 2b7b63b..410ff26 100644 --- a/tests/feature/test_scenario.py +++ b/tests/feature/test_scenario.py @@ -2,6 +2,8 @@ import pytest import re +import six + from pytest_bdd import ( scenario, given, @@ -13,29 +15,30 @@ from pytest_bdd import ( def test_scenario_not_found(request): """Test the situation when scenario is not found.""" - with pytest.raises(exceptions.ScenarioNotFound) as exc_info: scenario( 'not_found.feature', 'NOT FOUND' ) - assert exc_info.value.args[0].startswith('Scenario "NOT FOUND" in feature "[Empty]" in {feature_path}'.format( - feature_path=request.fspath.join('..', 'not_found.feature'))) + assert six.text_type(exc_info.value).startswith( + 'Scenario "NOT FOUND" in feature "[Empty]" in {feature_path}' + .format(feature_path=request.fspath.join('..', 'not_found.feature'))) @given('comments should be at the start of words') def comments(): + """Comments.""" pass @then(parsers.parse('this is not {acomment}')) def a_comment(acomment): + """A comment.""" assert re.search('a.*comment', acomment) def test_scenario_comments(request): """Test comments inside scenario.""" - @scenario( 'comments.feature', 'Comments'