Skip to content

Commit 5ce551e

Browse files
authored
Merge pull request #2075 from pytest-dev/master
Merge master into features after fixing flake8 errors
2 parents 7574033 + a3319ff commit 5ce551e

40 files changed

+307
-8
lines changed

CHANGELOG.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,10 @@ Changes
8181
Thanks `@RonnyPfannschmidt`_ for the report and `@nicoddemus`_ for the PR.
8282

8383
* Report teardown output on test failure (`#442`_).
84-
Thanks `@matclab`_ or the PR.
84+
Thanks `@matclab`_ for the PR.
8585

8686
* Fix teardown error message in generated xUnit XML.
87-
Thanks `@gdyuldin`_ or the PR.
87+
Thanks `@gdyuldin`_ for the PR.
8888

8989
* Properly handle exceptions in ``multiprocessing`` tasks (`#1984`_).
9090
Thanks `@adborden`_ for the report and `@nicoddemus`_ for the PR.

_pytest/_argcomplete.py

+1
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ def __call__(self, prefix, **kwargs):
8787
completion.append(x[prefix_dir:])
8888
return completion
8989

90+
9091
if os.environ.get('_ARGCOMPLETE'):
9192
try:
9293
import argcomplete.completers

_pytest/_code/code.py

+2
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,7 @@ def recursionindex(self):
343343
l.append(entry.frame.f_locals)
344344
return None
345345

346+
346347
co_equal = compile('__recursioncache_locals_1 == __recursioncache_locals_2',
347348
'?', 'eval')
348349

@@ -846,6 +847,7 @@ def getrawcode(obj, trycall=True):
846847
return x
847848
return obj
848849

850+
849851
if sys.version_info[:2] >= (3, 5): # RecursionError introduced in 3.5
850852
def is_recursion_error(excinfo):
851853
return excinfo.errisinstance(RecursionError) # noqa

_pytest/_code/source.py

+3
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ def findsource(obj):
265265
source.lines = [line.rstrip() for line in sourcelines]
266266
return source, lineno
267267

268+
268269
def getsource(obj, **kwargs):
269270
import _pytest._code
270271
obj = _pytest._code.getrawcode(obj)
@@ -275,6 +276,7 @@ def getsource(obj, **kwargs):
275276
assert isinstance(strsrc, str)
276277
return Source(strsrc, **kwargs)
277278

279+
278280
def deindent(lines, offset=None):
279281
if offset is None:
280282
for line in lines:
@@ -288,6 +290,7 @@ def deindent(lines, offset=None):
288290
if offset == 0:
289291
return list(lines)
290292
newlines = []
293+
291294
def readline_generator(lines):
292295
for line in lines:
293296
yield line + '\n'

_pytest/assertion/__init__.py

+2
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,12 @@ def install_importhook(config):
8080
config._assertstate.hook = hook = rewrite.AssertionRewritingHook(config)
8181
sys.meta_path.insert(0, hook)
8282
config._assertstate.trace('installed rewrite import hook')
83+
8384
def undo():
8485
hook = config._assertstate.hook
8586
if hook is not None and hook in sys.meta_path:
8687
sys.meta_path.remove(hook)
88+
8789
config.add_cleanup(undo)
8890
return hook
8991

_pytest/assertion/rewrite.py

+1
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@ def _write_pyc(state, co, source_stat, pyc):
276276
fp.close()
277277
return True
278278

279+
279280
RN = "\r\n".encode("utf-8")
280281
N = "\n".encode("utf-8")
281282

_pytest/capture.py

+1
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ def suspendcapture_item(self, item, when, in_=False):
153153
item.add_report_section(when, "stdout", out)
154154
item.add_report_section(when, "stderr", err)
155155

156+
156157
error_capsysfderror = "cannot use capsys and capfd at the same time"
157158

158159

_pytest/config.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,11 @@ def main(args=None, plugins=None):
6565
class cmdline: # compatibility namespace
6666
main = staticmethod(main)
6767

68+
6869
class UsageError(Exception):
6970
""" error in pytest usage or invocation"""
7071

72+
7173
_preinit = []
7274

7375
default_plugins = (
@@ -594,7 +596,7 @@ def __init__(self, *names, **attrs):
594596
if typ == 'choice':
595597
warnings.warn(
596598
'type argument to addoption() is a string %r.'
597-
' For parsearg this is optional and when supplied '
599+
' For parsearg this is optional and when supplied'
598600
' should be a type.'
599601
' (options: %s)' % (typ, names),
600602
DeprecationWarning,
@@ -818,9 +820,11 @@ class Notset:
818820
def __repr__(self):
819821
return "<NOTSET>"
820822

823+
821824
notset = Notset()
822825
FILE_OR_DIR = 'file_or_dir'
823826

827+
824828
class Config(object):
825829
""" access to configuration values, pluginmanager and plugin hooks. """
826830

@@ -843,9 +847,11 @@ def __init__(self, pluginmanager):
843847
self._warn = self.pluginmanager._warn
844848
self.pluginmanager.register(self, "pytestconfig")
845849
self._configured = False
850+
846851
def do_setns(dic):
847852
import pytest
848853
setns(pytest, dic)
854+
849855
self.hook.pytest_namespace.call_historic(do_setns, {})
850856
self.hook.pytest_addoption.call_historic(kwargs=dict(parser=self._parser))
851857

_pytest/debugging.py

+2
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,12 @@ def pytest_configure(config):
3131
config.pluginmanager.register(PdbInvoke(), 'pdbinvoke')
3232

3333
old = (pdb.set_trace, pytestPDB._pluginmanager)
34+
3435
def fin():
3536
pdb.set_trace, pytestPDB._pluginmanager = old
3637
pytestPDB._config = None
3738
pytestPDB._pdb_cls = pdb.Pdb
39+
3840
pdb.set_trace = pytest.set_trace
3941
pytestPDB._pluginmanager = config.pluginmanager
4042
pytestPDB._config = config

_pytest/fixtures.py

+2
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,13 @@ def pytest_sessionstart(session):
3232
def scopeproperty(name=None, doc=None):
3333
def decoratescope(func):
3434
scopename = name or func.__name__
35+
3536
def provide(self):
3637
if func.__name__ in scope2props[self.scope]:
3738
return func(self)
3839
raise AttributeError("%s not available in %s-scoped context" % (
3940
scopename, self.scope))
41+
4042
return property(provide, None, None, func.__doc__)
4143
return decoratescope
4244

_pytest/helpconfig.py

+2
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,14 @@ def pytest_cmdline_parse():
4141
config.trace.root.setwriter(debugfile.write)
4242
undo_tracing = config.pluginmanager.enable_tracing()
4343
sys.stderr.write("writing pytestdebug information to %s\n" % path)
44+
4445
def unset_tracing():
4546
debugfile.close()
4647
sys.stderr.write("wrote pytestdebug information to %s\n" %
4748
debugfile.name)
4849
config.trace.root.setwriter(None)
4950
undo_tracing()
51+
5052
config.add_cleanup(unset_tracing)
5153

5254
def pytest_cmdline_main(config):

_pytest/junitxml.py

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
class Junit(py.xml.Namespace):
2828
pass
2929

30+
3031
# We need to get the subset of the invalid unicode ranges according to
3132
# XML 1.0 which are valid in this python build. Hence we calculate
3233
# this dynamically instead of hardcoding it. The spec range of valid

_pytest/mark.py

+2
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ def pytest_cmdline_main(config):
6060
tw.line()
6161
config._ensure_unconfigure()
6262
return 0
63+
64+
6365
pytest_cmdline_main.tryfirst = True
6466

6567

_pytest/pastebin.py

+6
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ def pytest_addoption(parser):
1111
choices=['failed', 'all'],
1212
help="send failed|all info to bpaste.net pastebin service.")
1313

14+
1415
@pytest.hookimpl(trylast=True)
1516
def pytest_configure(config):
1617
import py
@@ -23,13 +24,16 @@ def pytest_configure(config):
2324
# pastebin file will be utf-8 encoded binary file
2425
config._pastebinfile = tempfile.TemporaryFile('w+b')
2526
oldwrite = tr._tw.write
27+
2628
def tee_write(s, **kwargs):
2729
oldwrite(s, **kwargs)
2830
if py.builtin._istext(s):
2931
s = s.encode('utf-8')
3032
config._pastebinfile.write(s)
33+
3134
tr._tw.write = tee_write
3235

36+
3337
def pytest_unconfigure(config):
3438
if hasattr(config, '_pastebinfile'):
3539
# get terminal contents and delete file
@@ -45,6 +49,7 @@ def pytest_unconfigure(config):
4549
pastebinurl = create_new_paste(sessionlog)
4650
tr.write_line("pastebin session-log: %s\n" % pastebinurl)
4751

52+
4853
def create_new_paste(contents):
4954
"""
5055
Creates a new paste using bpaste.net service.
@@ -72,6 +77,7 @@ def create_new_paste(contents):
7277
else:
7378
return 'bad response: ' + response
7479

80+
7581
def pytest_terminal_summary(terminalreporter):
7682
import _pytest.config
7783
if terminalreporter.config.option.pastebin != "failed":

_pytest/pytester.py

+8
Original file line numberDiff line numberDiff line change
@@ -482,10 +482,12 @@ def _makefile(self, ext, args, kwargs):
482482
for name, value in items:
483483
p = self.tmpdir.join(name).new(ext=ext)
484484
source = Source(value)
485+
485486
def my_totext(s, encoding="utf-8"):
486487
if py.builtin._isbytes(s):
487488
s = py.builtin._totext(s, encoding=encoding)
488489
return s
490+
489491
source_unicode = "\n".join([my_totext(line) for line in source.lines])
490492
source = py.builtin._totext(source_unicode)
491493
content = source.strip().encode("utf-8") # + "\n"
@@ -695,12 +697,15 @@ def inline_run(self, *args, **kwargs):
695697
# warning which will trigger to say they can no longer be
696698
# re-written, which is fine as they are already re-written.
697699
orig_warn = AssertionRewritingHook._warn_already_imported
700+
698701
def revert():
699702
AssertionRewritingHook._warn_already_imported = orig_warn
703+
700704
self.request.addfinalizer(revert)
701705
AssertionRewritingHook._warn_already_imported = lambda *a: None
702706

703707
rec = []
708+
704709
class Collect:
705710
def pytest_configure(x, config):
706711
rec.append(self.make_hook_recorder(config.pluginmanager))
@@ -735,10 +740,13 @@ def runpytest_inprocess(self, *args, **kwargs):
735740
try:
736741
reprec = self.inline_run(*args, **kwargs)
737742
except SystemExit as e:
743+
738744
class reprec:
739745
ret = e.args[0]
746+
740747
except Exception:
741748
traceback.print_exc()
749+
742750
class reprec:
743751
ret = 3
744752
finally:

_pytest/python.py

+3
Original file line numberDiff line numberDiff line change
@@ -214,9 +214,12 @@ def fget(self):
214214
if obj is None:
215215
self._obj = obj = self._getobj()
216216
return obj
217+
217218
def fset(self, value):
218219
self._obj = value
220+
219221
return property(fget, fset, None, "underlying python object")
222+
220223
obj = obj()
221224

222225
def _getobj(self):

_pytest/runner.py

+7
Original file line numberDiff line numberDiff line change
@@ -517,8 +517,10 @@ def exit(msg):
517517
__tracebackhide__ = True
518518
raise Exit(msg)
519519

520+
520521
exit.Exception = Exit
521522

523+
522524
def skip(msg=""):
523525
""" skip an executing test with the given message. Note: it's usually
524526
better to use the pytest.mark.skipif marker to declare a test to be
@@ -527,8 +529,11 @@ def skip(msg=""):
527529
"""
528530
__tracebackhide__ = True
529531
raise Skipped(msg=msg)
532+
533+
530534
skip.Exception = Skipped
531535

536+
532537
def fail(msg="", pytrace=True):
533538
""" explicitly fail an currently-executing test with the given Message.
534539
@@ -537,6 +542,8 @@ def fail(msg="", pytrace=True):
537542
"""
538543
__tracebackhide__ = True
539544
raise Failed(msg=msg, pytrace=pytrace)
545+
546+
540547
fail.Exception = Failed
541548

542549

_pytest/skipping.py

+4
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@ def pytest_configure(config):
2525
if config.option.runxfail:
2626
old = pytest.xfail
2727
config._cleanup.append(lambda: setattr(pytest, "xfail", old))
28+
2829
def nop(*args, **kwargs):
2930
pass
31+
3032
nop.Exception = XFailed
3133
setattr(pytest, "xfail", nop)
3234

@@ -65,6 +67,8 @@ def xfail(reason=""):
6567
""" xfail an executing test or setup functions with the given reason."""
6668
__tracebackhide__ = True
6769
raise XFailed(reason)
70+
71+
6872
xfail.Exception = XFailed
6973

7074

_pytest/tmpdir.py

+1
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ def get_user():
8181
except (ImportError, KeyError):
8282
return None
8383

84+
8485
# backward compatibility
8586
TempdirHandler = TempdirFactory
8687

_pytest/unittest.py

+2
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ def pytest_runtest_protocol(item):
186186
ut = sys.modules['twisted.python.failure']
187187
Failure__init__ = ut.Failure.__init__
188188
check_testcase_implements_trial_reporter()
189+
189190
def excstore(self, exc_value=None, exc_type=None, exc_tb=None,
190191
captureVars=None):
191192
if exc_value is None:
@@ -199,6 +200,7 @@ def excstore(self, exc_value=None, exc_type=None, exc_tb=None,
199200
captureVars=captureVars)
200201
except TypeError:
201202
Failure__init__(self, exc_value, exc_type, exc_tb)
203+
202204
ut.Failure.__init__ = excstore
203205
yield
204206
ut.Failure.__init__ = Failure__init__

testing/code/test_code.py

+5
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class A:
2424
pass
2525
pytest.raises(TypeError, "_pytest._code.Code(A)")
2626

27+
2728
if True:
2829
def x():
2930
pass
@@ -68,8 +69,10 @@ def test_code_from_func():
6869

6970
def test_unicode_handling():
7071
value = py.builtin._totext('\xc4\x85\xc4\x87\n', 'utf-8').encode('utf8')
72+
7173
def f():
7274
raise Exception(value)
75+
7376
excinfo = pytest.raises(Exception, f)
7477
str(excinfo)
7578
if sys.version_info[0] < 3:
@@ -79,8 +82,10 @@ def f():
7982
@pytest.mark.skipif(sys.version_info[0] >= 3, reason='python 2 only issue')
8083
def test_unicode_handling_syntax_error():
8184
value = py.builtin._totext('\xc4\x85\xc4\x87\n', 'utf-8').encode('utf8')
85+
8286
def f():
8387
raise SyntaxError('invalid syntax', (None, 1, 3, value))
88+
8489
excinfo = pytest.raises(Exception, f)
8590
str(excinfo)
8691
if sys.version_info[0] < 3:

0 commit comments

Comments
 (0)