Fixed FeatureError string representation to correctly support python3. closes #115

This commit is contained in:
Anatoly Bubenkov 2015-06-04 10:28:48 +02:00
parent 94b90ef0d9
commit 24684bfb82
4 changed files with 16 additions and 7 deletions

View File

@ -14,5 +14,6 @@ These people have contributed to `pytest-bdd`, in alphabetical order:
* `Dmitrijs Milajevs <dimazest@gmail.com>`_
* `Floris Bruynooghe <flub@devork.be>`_
* `Harro van der Klauw <hvdklauw@gmail.com>`_
* `Laurence Rowe <l@lrowe.co.uk>`_
* `Leonardo Santagada <santagada@github.com>`_
* `Robin Pedersen <ropez@github.com>`_

View File

@ -1,6 +1,11 @@
Changelog
=========
2.9.1
-----
- Fixed FeatureError string representation to correctly support python3 (bubenkoff, lrowe)
2.9.0
-----

View File

@ -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)

View File

@ -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'