Skip to content

Commit 5d58fe3

Browse files
youtuxKonstantin Goloveshko
andauthored
Merge pull request #406 from elchupanebrej/actual_python_pytest
- Drop support of python 2.7, 3.5; Add explicit support for python >=3.6 - Remove six dependency Co-authored-by: Konstantin Goloveshko <[email protected]>
2 parents 7cb344e + e1dc0ca commit 5d58fe3

27 files changed

+141
-269
lines changed

.travis.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
dist: bionic
22
language: python
33
python:
4-
- '2.7'
5-
- '3.5'
64
- '3.6'
75
- '3.7'
86
- '3.8'
7+
- '3.9'
98
install: pip install tox tox-travis coverage codecov
109
script: tox --recreate
1110
branches:

CHANGES.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
Changelog
22
=========
33

4+
Unreleased
5+
-----------
6+
- Drop compatibility for python 2 and officially support only python >= 3.6.
7+
48
4.0.2
59
-----
610
- Fix a bug that prevents using comments in the ``Examples:`` section. (youtux)

docs/conf.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
#
32
# Pytest-BDD documentation build configuration file, created by
43
# sphinx-quickstart on Sun Apr 7 21:07:56 2013.
@@ -15,7 +14,8 @@
1514
# add these directories to sys.path here. If the directory is relative to the
1615
# documentation root, use os.path.abspath to make it absolute, like shown here.
1716

18-
import sys, os
17+
import os
18+
import sys
1919

2020
sys.path.insert(0, os.path.abspath(".."))
2121

@@ -43,8 +43,8 @@
4343
master_doc = "index"
4444

4545
# General information about the project.
46-
project = u"Pytest-BDD"
47-
copyright = u"2013, Oleg Pidsadnyi"
46+
project = "Pytest-BDD"
47+
copyright = "2013, Oleg Pidsadnyi"
4848

4949
# The version info for the project you're documenting, acts as replacement for
5050
# |version| and |release|, also used in various other places throughout the
@@ -183,7 +183,7 @@
183183

184184
# Grouping the document tree into LaTeX files. List of tuples
185185
# (source start file, target name, title, author, documentclass [howto/manual]).
186-
latex_documents = [("index", "Pytest-BDD.tex", u"Pytest-BDD Documentation", u"Oleg Pidsadnyi", "manual")]
186+
latex_documents = [("index", "Pytest-BDD.tex", "Pytest-BDD Documentation", "Oleg Pidsadnyi", "manual")]
187187

188188
# The name of an image file (relative to this directory) to place at the top of
189189
# the title page.
@@ -210,7 +210,7 @@
210210

211211
# One entry per manual page. List of tuples
212212
# (source start file, name, description, authors, manual section).
213-
man_pages = [("index", "pytest-bdd", u"Pytest-BDD Documentation", [u"Oleg Pidsadnyi"], 1)]
213+
man_pages = [("index", "pytest-bdd", "Pytest-BDD Documentation", ["Oleg Pidsadnyi"], 1)]
214214

215215
# If true, show URL addresses after external links.
216216
# man_show_urls = False
@@ -225,8 +225,8 @@
225225
(
226226
"index",
227227
"Pytest-BDD",
228-
u"Pytest-BDD Documentation",
229-
u"Oleg Pidsadnyi",
228+
"Pytest-BDD Documentation",
229+
"Oleg Pidsadnyi",
230230
"Pytest-BDD",
231231
"One line description of project.",
232232
"Miscellaneous",

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[tool.black]
22
line-length = 120
3-
target-version = ['py27', 'py35', 'py36', 'py37', 'py38']
3+
target-version = ['py36', 'py37', 'py38']

pytest_bdd/cucumber_json.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
"""Cucumber json output formatter."""
22

3-
import codecs
43
import json
54
import math
65
import os
7-
import sys
86
import time
97

10-
from .feature import force_unicode
11-
128

139
def add_options(parser):
1410
"""Add pytest-bdd options."""
@@ -72,7 +68,7 @@ def _get_result(self, step, report, error_message=False):
7268
if report.passed or not step["failed"]: # ignore setup/teardown
7369
result = {"status": "passed"}
7470
elif report.failed and step["failed"]:
75-
result = {"status": "failed", "error_message": force_unicode(report.longrepr) if error_message else ""}
71+
result = {"status": "failed", "error_message": str(report.longrepr) if error_message else ""}
7672
elif report.skipped:
7773
result = {"status": "skipped"}
7874
result["duration"] = int(math.floor((10 ** 9) * step["duration"])) # nanosec
@@ -171,11 +167,7 @@ def pytest_sessionstart(self):
171167
self.suite_start_time = time.time()
172168

173169
def pytest_sessionfinish(self):
174-
if sys.version_info[0] < 3:
175-
logfile_open = codecs.open
176-
else:
177-
logfile_open = open
178-
with logfile_open(self.logfile, "w", encoding="utf-8") as logfile:
170+
with open(self.logfile, "w", encoding="utf-8") as logfile:
179171
logfile.write(json.dumps(list(self.features.values())))
180172

181173
def pytest_terminal_summary(self, terminalreporter):

pytest_bdd/exceptions.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
"""pytest-bdd Exceptions."""
2-
import six
32

43

54
class ScenarioIsDecoratorOnly(Exception):
@@ -30,19 +29,14 @@ class StepDefinitionNotFoundError(Exception):
3029
"""Step definition not found."""
3130

3231

33-
class InvalidStepParserError(Exception):
34-
"""Invalid step parser."""
35-
36-
3732
class NoScenariosFound(Exception):
3833
"""No scenarios found."""
3934

4035

41-
@six.python_2_unicode_compatible
4236
class FeatureError(Exception):
4337
"""Feature parse error."""
4438

45-
message = u"{0}.\nLine number: {1}.\nLine: {2}.\nFile: {3}"
39+
message = "{0}.\nLine number: {1}.\nLine: {2}.\nFile: {3}"
4640

4741
def __str__(self):
4842
"""String representation."""

pytest_bdd/feature.py

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -24,47 +24,15 @@
2424
one line.
2525
"""
2626
import os.path
27-
import sys
2827

2928
import glob2
3029

3130
from .parser import parse_feature
3231

33-
3432
# Global features dictionary
3533
features = {}
3634

3735

38-
def force_unicode(obj, encoding="utf-8"):
39-
"""Get the unicode string out of given object (python 2 and python 3).
40-
41-
:param obj: An `object`, usually a string.
42-
43-
:return: unicode string.
44-
"""
45-
if sys.version_info < (3, 0):
46-
if isinstance(obj, str):
47-
return obj.decode(encoding)
48-
else:
49-
return unicode(obj)
50-
else: # pragma: no cover
51-
return str(obj)
52-
53-
54-
def force_encode(string, encoding="utf-8"):
55-
"""Force string encoding (Python compatibility function).
56-
57-
:param str string: A string value.
58-
:param str encoding: Encoding.
59-
60-
:return: Encoded string.
61-
"""
62-
if sys.version_info < (3, 0):
63-
if isinstance(string, unicode):
64-
string = string.encode(encoding)
65-
return string
66-
67-
6836
def get_feature(base_path, filename, encoding="utf-8"):
6937
"""Get a feature by the filename.
7038

pytest_bdd/generation.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,14 @@
33
import itertools
44
import os.path
55

6-
from mako.lookup import TemplateLookup
76
import py
7+
from mako.lookup import TemplateLookup
88

9+
from .feature import get_features
910
from .scenario import find_argumented_step_fixture_name, make_python_docstring, make_python_name, make_string_literal
1011
from .steps import get_step_fixture_name
11-
from .feature import get_features
1212
from .types import STEP_TYPES
1313

14-
1514
template_lookup = TemplateLookup(directories=[os.path.join(os.path.dirname(__file__), "templates")])
1615

1716

@@ -109,19 +108,19 @@ def print_missing_code(scenarios, steps):
109108
tw.write(code)
110109

111110

112-
def _find_step_fixturedef(fixturemanager, item, name, type_, encoding="utf-8"):
111+
def _find_step_fixturedef(fixturemanager, item, name, type_):
113112
"""Find step fixturedef.
114113
115114
:param request: PyTest Item object.
116115
:param step: `Step`.
117116
118117
:return: Step function.
119118
"""
120-
fixturedefs = fixturemanager.getfixturedefs(get_step_fixture_name(name, type_, encoding), item.nodeid)
119+
fixturedefs = fixturemanager.getfixturedefs(get_step_fixture_name(name, type_), item.nodeid)
121120
if not fixturedefs:
122121
name = find_argumented_step_fixture_name(name, type_, fixturemanager)
123122
if name:
124-
return _find_step_fixturedef(fixturemanager, item, name, encoding)
123+
return _find_step_fixturedef(fixturemanager, item, name, type_)
125124
else:
126125
return fixturedefs
127126

pytest_bdd/gherkin_terminal_reporter.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
# -*- encoding: utf-8 -*-
2-
3-
from __future__ import unicode_literals
4-
51
import re
62

73
from _pytest.terminal import TerminalReporter

pytest_bdd/parser.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
import textwrap
55
from collections import OrderedDict
66

7-
import six
8-
97
from . import types, exceptions
108

119
SPLIT_LINE_RE = re.compile(r"(?<!\\)\|")
@@ -193,7 +191,7 @@ def parse_feature(basedir, filename, encoding="utf-8"):
193191
target.add_step(step)
194192
prev_line = clean_line
195193

196-
feature.description = u"\n".join(description).strip()
194+
feature.description = "\n".join(description).strip()
197195
return feature
198196

199197

@@ -292,7 +290,6 @@ def validate(self):
292290
)
293291

294292

295-
@six.python_2_unicode_compatible
296293
class Step(object):
297294

298295
"""Step."""
@@ -447,9 +444,6 @@ def __bool__(self):
447444
"""Bool comparison."""
448445
return bool(self.vertical_examples or self.examples)
449446

450-
if six.PY2:
451-
__nonzero__ = __bool__
452-
453447

454448
def get_tags(line):
455449
"""Get tags out of the given line.

0 commit comments

Comments
 (0)