Skip to content

Commit 9b51fc6

Browse files
Merge pull request #2526 from nicoddemus/merge-master-into-features
Merge master into features
2 parents 6eeab45 + 3de9365 commit 9b51fc6

38 files changed

+401
-226
lines changed

CHANGELOG.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ Bug Fixes
2525
- ``UnicodeWarning`` is issued from the internal pytest warnings plugin only
2626
when the message contains non-ascii unicode (Python 2 only). (#2463)
2727

28-
- Added a workaround for Python 3.6 WindowsConsoleIO breaking due to Pytests's
29-
FDCapture. Other code using console handles might still be affected by the
30-
very same issue and might require further workarounds/fixes, i.e. colorama.
28+
- Added a workaround for Python 3.6 ``WindowsConsoleIO`` breaking due to Pytests's
29+
``FDCapture``. Other code using console handles might still be affected by the
30+
very same issue and might require further workarounds/fixes, i.e. ``colorama``.
3131
(#2467)
3232

3333

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2004-2016 Holger Krekel and others
3+
Copyright (c) 2004-2017 Holger Krekel and others
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy of
66
this software and associated documentation files (the "Software"), to deal in

MANIFEST.in

Lines changed: 0 additions & 39 deletions
This file was deleted.

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ Consult the `Changelog <http://docs.pytest.org/en/latest/changelog.html>`__ page
102102
License
103103
-------
104104

105-
Copyright Holger Krekel and others, 2004-2016.
105+
Copyright Holger Krekel and others, 2004-2017.
106106

107107
Distributed under the terms of the `MIT`_ license, pytest is free and open source software.
108108

_pytest/_code/code.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -640,8 +640,11 @@ def _truncate_recursive_traceback(self, traceback):
640640
).format(exc_type=type(e).__name__, exc_msg=safe_str(e), max_frames=max_frames, total=len(traceback))
641641
traceback = traceback[:max_frames] + traceback[-max_frames:]
642642
else:
643-
extraline = "!!! Recursion detected (same locals & position)"
644-
traceback = traceback[:recursionindex + 1]
643+
if recursionindex is not None:
644+
extraline = "!!! Recursion detected (same locals & position)"
645+
traceback = traceback[:recursionindex + 1]
646+
else:
647+
extraline = None
645648

646649
return traceback, extraline
647650

_pytest/assertion/rewrite.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,6 @@ def _should_rewrite(self, name, fn_pypath, state):
162162
# modules not passed explicitly on the command line are only
163163
# rewritten if they match the naming convention for test files
164164
for pat in self.fnpats:
165-
# use fnmatch instead of fn_pypath.fnmatch because the
166-
# latter might trigger an import to fnmatch.fnmatch
167-
# internally, which would cause this method to be
168-
# called recursively
169165
if fn_pypath.fnmatch(pat):
170166
state.trace("matched test file %r" % (fn,))
171167
return True

_pytest/doctest.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,6 @@ def collect(self):
177177
name = self.fspath.basename
178178
globs = {'__name__': '__main__'}
179179

180-
181180
optionflags = get_optionflags(self)
182181
runner = doctest.DebugRunner(verbose=0, optionflags=optionflags,
183182
checker=_get_checker())
@@ -218,9 +217,6 @@ def collect(self):
218217
runner = doctest.DebugRunner(verbose=0, optionflags=optionflags,
219218
checker=_get_checker())
220219

221-
encoding = self.config.getini("doctest_encoding")
222-
_fix_spoof_python2(runner, encoding)
223-
224220
for test in finder.find(module, module.__name__):
225221
if test.examples: # skip empty doctests
226222
yield DoctestItem(test.name, self, runner, test)
@@ -332,7 +328,10 @@ def _get_report_choice(key):
332328

333329
def _fix_spoof_python2(runner, encoding):
334330
"""
335-
Installs a "SpoofOut" into the given DebugRunner so it properly deals with unicode output.
331+
Installs a "SpoofOut" into the given DebugRunner so it properly deals with unicode output. This
332+
should patch only doctests for text files because they don't have a way to declare their
333+
encoding. Doctests in docstrings from Python modules don't have the same problem given that
334+
Python already decoded the strings.
336335
337336
This fixes the problem related in issue #2434.
338337
"""

_pytest/fixtures.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -733,10 +733,19 @@ def addfinalizer(self, finalizer):
733733
self._finalizer.append(finalizer)
734734

735735
def finish(self):
736+
exceptions = []
736737
try:
737738
while self._finalizer:
738-
func = self._finalizer.pop()
739-
func()
739+
try:
740+
func = self._finalizer.pop()
741+
func()
742+
except:
743+
exceptions.append(sys.exc_info())
744+
if exceptions:
745+
e = exceptions[0]
746+
del exceptions # ensure we don't keep all frames alive because of the traceback
747+
py.builtin._reraise(*e)
748+
740749
finally:
741750
ihook = self._fixturemanager.session.ihook
742751
ihook.pytest_fixture_post_finalizer(fixturedef=self)

_pytest/hookspec.py

Lines changed: 44 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,19 @@ def pytest_configure(config):
7373

7474
@hookspec(firstresult=True)
7575
def pytest_cmdline_parse(pluginmanager, args):
76-
"""return initialized config object, parsing the specified args. """
76+
"""return initialized config object, parsing the specified args.
77+
78+
Stops at first non-None result, see :ref:`firstresult` """
7779

7880
def pytest_cmdline_preparse(config, args):
7981
"""(deprecated) modify command line arguments before option parsing. """
8082

8183
@hookspec(firstresult=True)
8284
def pytest_cmdline_main(config):
8385
""" called for performing the main command line action. The default
84-
implementation will invoke the configure hooks and runtest_mainloop. """
86+
implementation will invoke the configure hooks and runtest_mainloop.
87+
88+
Stops at first non-None result, see :ref:`firstresult` """
8589

8690
def pytest_load_initial_conftests(early_config, parser, args):
8791
""" implements the loading of initial conftest files ahead
@@ -94,7 +98,9 @@ def pytest_load_initial_conftests(early_config, parser, args):
9498

9599
@hookspec(firstresult=True)
96100
def pytest_collection(session):
97-
""" perform the collection protocol for the given session. """
101+
""" perform the collection protocol for the given session.
102+
103+
Stops at first non-None result, see :ref:`firstresult` """
98104

99105
def pytest_collection_modifyitems(session, config, items):
100106
""" called after collection has been performed, may filter or re-order
@@ -108,11 +114,15 @@ def pytest_ignore_collect(path, config):
108114
""" return True to prevent considering this path for collection.
109115
This hook is consulted for all files and directories prior to calling
110116
more specific hooks.
117+
118+
Stops at first non-None result, see :ref:`firstresult`
111119
"""
112120

113121
@hookspec(firstresult=True)
114122
def pytest_collect_directory(path, parent):
115-
""" called before traversing a directory for collection files. """
123+
""" called before traversing a directory for collection files.
124+
125+
Stops at first non-None result, see :ref:`firstresult` """
116126

117127
def pytest_collect_file(path, parent):
118128
""" return collection Node or None for the given path. Any new node
@@ -133,7 +143,9 @@ def pytest_deselected(items):
133143

134144
@hookspec(firstresult=True)
135145
def pytest_make_collect_report(collector):
136-
""" perform ``collector.collect()`` and return a CollectReport. """
146+
""" perform ``collector.collect()`` and return a CollectReport.
147+
148+
Stops at first non-None result, see :ref:`firstresult` """
137149

138150
# -------------------------------------------------------------------------
139151
# Python test function related hooks
@@ -145,15 +157,20 @@ def pytest_pycollect_makemodule(path, parent):
145157
This hook will be called for each matching test module path.
146158
The pytest_collect_file hook needs to be used if you want to
147159
create test modules for files that do not match as a test module.
148-
"""
160+
161+
Stops at first non-None result, see :ref:`firstresult` """
149162

150163
@hookspec(firstresult=True)
151164
def pytest_pycollect_makeitem(collector, name, obj):
152-
""" return custom item/collector for a python object in a module, or None. """
165+
""" return custom item/collector for a python object in a module, or None.
166+
167+
Stops at first non-None result, see :ref:`firstresult` """
153168

154169
@hookspec(firstresult=True)
155170
def pytest_pyfunc_call(pyfuncitem):
156-
""" call underlying test function. """
171+
""" call underlying test function.
172+
173+
Stops at first non-None result, see :ref:`firstresult` """
157174

158175
def pytest_generate_tests(metafunc):
159176
""" generate (multiple) parametrized calls to a test function."""
@@ -163,7 +180,8 @@ def pytest_make_parametrize_id(config, val, argname):
163180
"""Return a user-friendly string representation of the given ``val`` that will be used
164181
by @pytest.mark.parametrize calls. Return None if the hook doesn't know about ``val``.
165182
The parameter name is available as ``argname``, if required.
166-
"""
183+
184+
Stops at first non-None result, see :ref:`firstresult` """
167185

168186
# -------------------------------------------------------------------------
169187
# generic runtest related hooks
@@ -172,7 +190,9 @@ def pytest_make_parametrize_id(config, val, argname):
172190
@hookspec(firstresult=True)
173191
def pytest_runtestloop(session):
174192
""" called for performing the main runtest loop
175-
(after collection finished). """
193+
(after collection finished).
194+
195+
Stops at first non-None result, see :ref:`firstresult` """
176196

177197
def pytest_itemstart(item, node):
178198
""" (deprecated, use pytest_runtest_logstart). """
@@ -190,7 +210,9 @@ def pytest_runtest_protocol(item, nextitem):
190210
:py:func:`pytest_runtest_teardown`.
191211
192212
:return boolean: True if no further hook implementations should be invoked.
193-
"""
213+
214+
215+
Stops at first non-None result, see :ref:`firstresult` """
194216

195217
def pytest_runtest_logstart(nodeid, location):
196218
""" signal the start of running a single test item. """
@@ -215,7 +237,8 @@ def pytest_runtest_makereport(item, call):
215237
""" return a :py:class:`_pytest.runner.TestReport` object
216238
for the given :py:class:`pytest.Item <_pytest.main.Item>` and
217239
:py:class:`_pytest.runner.CallInfo`.
218-
"""
240+
241+
Stops at first non-None result, see :ref:`firstresult` """
219242

220243
def pytest_runtest_logreport(report):
221244
""" process a test setup/call/teardown report relating to
@@ -227,7 +250,9 @@ def pytest_runtest_logreport(report):
227250

228251
@hookspec(firstresult=True)
229252
def pytest_fixture_setup(fixturedef, request):
230-
""" performs fixture setup execution. """
253+
""" performs fixture setup execution.
254+
255+
Stops at first non-None result, see :ref:`firstresult` """
231256

232257
def pytest_fixture_post_finalizer(fixturedef):
233258
""" called after fixture teardown, but before the cache is cleared so
@@ -277,7 +302,9 @@ def pytest_report_header(config, startdir):
277302

278303
@hookspec(firstresult=True)
279304
def pytest_report_teststatus(report):
280-
""" return result-category, shortletter and verbose word for reporting."""
305+
""" return result-category, shortletter and verbose word for reporting.
306+
307+
Stops at first non-None result, see :ref:`firstresult` """
281308

282309
def pytest_terminal_summary(terminalreporter, exitstatus):
283310
""" add additional section in terminal summary reporting. """
@@ -295,7 +322,9 @@ def pytest_logwarning(message, code, nodeid, fslocation):
295322

296323
@hookspec(firstresult=True)
297324
def pytest_doctest_prepare_content(content):
298-
""" return processed content for a given doctest"""
325+
""" return processed content for a given doctest
326+
327+
Stops at first non-None result, see :ref:`firstresult` """
299328

300329
# -------------------------------------------------------------------------
301330
# error handling and internal debugging hooks

_pytest/main.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -763,7 +763,11 @@ def _matchnodes(self, matching, names):
763763
if not has_matched and len(rep.result) == 1 and x.name == "()":
764764
nextnames.insert(0, name)
765765
resultnodes.extend(self.matchnodes([x], nextnames))
766-
node.ihook.pytest_collectreport(report=rep)
766+
else:
767+
# report collection failures here to avoid failing to run some test
768+
# specified in the command line because the module could not be
769+
# imported (#134)
770+
node.ihook.pytest_collectreport(report=rep)
767771
return resultnodes
768772

769773
def genitems(self, node):

0 commit comments

Comments
 (0)