Skip to content

Commit 9646a1c

Browse files
committed
Merge remote-tracking branch 'upstream/master' into merge-master-into-features
2 parents 58b6e86 + 9087ac4 commit 9646a1c

21 files changed

+177
-103
lines changed

.github/PULL_REQUEST_TEMPLATE.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Thanks for submitting a PR, your contribution is really appreciated!
33
Here's a quick checklist that should be present in PRs (you can delete this text from the final description, this is
44
just a guideline):
55

6-
- [ ] Create a new changelog file in the `changelog` folder, with a name like `<ISSUE NUMBER>.<TYPE>.rst`. See [changelog/README.rst](/changelog/README.rst) for details.
6+
- [ ] Create a new changelog file in the `changelog` folder, with a name like `<ISSUE NUMBER>.<TYPE>.rst`. See [changelog/README.rst](https://github.com/pytest-dev/pytest/blob/master/changelog/README.rst) for details.
77
- [ ] Target the `master` branch for bug fixes, documentation updates and trivial changes.
88
- [ ] Target the `features` branch for new features and removals/deprecations.
99
- [ ] Include documentation when adding new features.

.travis.yml

+5-9
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,15 @@ install:
1212
- pip install --upgrade --pre tox
1313
env:
1414
matrix:
15-
# note: please use "tox --listenvs" to populate the build matrix below
16-
# please remove the linting env in all cases
17-
- TOXENV=py27-pexpect
15+
# Specialized factors for py27.
16+
- TOXENV=py27-pexpect,py27-trial,py27-numpy
17+
- TOXENV=py27-nobyte
1818
- TOXENV=py27-xdist
19-
- TOXENV=py27-trial
20-
- TOXENV=py27-numpy
2119
- TOXENV=py27-pluggymaster PYTEST_NO_COVERAGE=1
22-
- TOXENV=py36-pexpect
20+
# Specialized factors for py36.
21+
- TOXENV=py36-pexpect,py36-trial,py36-numpy
2322
- TOXENV=py36-xdist
24-
- TOXENV=py36-trial
25-
- TOXENV=py36-numpy
2623
- TOXENV=py36-pluggymaster PYTEST_NO_COVERAGE=1
27-
- TOXENV=py27-nobyte
2824

2925
jobs:
3026
include:

AUTHORS

+1
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ Thomas Hisch
211211
Tim Strazny
212212
Tom Dalton
213213
Tom Viner
214+
Tomer Keren
214215
Trevor Bekolay
215216
Tyler Goodlet
216217
Tzu-ping Chung

CONTRIBUTING.rst

+41
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,47 @@ Here is a simple overview, with pytest-specific bits:
280280
base: features # if it's a feature
281281

282282

283+
Writing Tests
284+
----------------------------
285+
286+
Writing tests for plugins or for pytest itself is often done using the `testdir fixture <https://docs.pytest.org/en/latest/reference.html#testdir>`_, as a "black-box" test.
287+
288+
For example, to ensure a simple test passes you can write:
289+
290+
.. code-block:: python
291+
292+
def test_true_assertion(testdir):
293+
testdir.makepyfile(
294+
"""
295+
def test_foo():
296+
assert True
297+
"""
298+
)
299+
result = testdir.runpytest()
300+
result.assert_outcomes(failed=0, passed=1)
301+
302+
303+
Alternatively, it is possible to make checks based on the actual output of the termal using
304+
*glob-like* expressions:
305+
306+
.. code-block:: python
307+
308+
def test_true_assertion(testdir):
309+
testdir.makepyfile(
310+
"""
311+
def test_foo():
312+
assert False
313+
"""
314+
)
315+
result = testdir.runpytest()
316+
result.stdout.fnmatch_lines(["*assert False*", "*1 failed*"])
317+
318+
When choosing a file where to write a new test, take a look at the existing files and see if there's
319+
one file which looks like a good fit. For example, a regression test about a bug in the ``--lf`` option
320+
should go into ``test_cacheprovider.py``, given that this option is implemented in ``cacheprovider.py``.
321+
If in doubt, go ahead and open a PR with your best guess and we can discuss this over the code.
322+
323+
283324
Joining the Development Team
284325
----------------------------
285326

appveyor.yml

+14-12
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,29 @@
11
environment:
22
matrix:
3-
- TOXENV: "linting,docs,doctesting"
4-
PYTEST_NO_COVERAGE: "1"
53
- TOXENV: "py27"
6-
- TOXENV: "py34"
7-
- TOXENV: "py35"
8-
- TOXENV: "py36"
94
- TOXENV: "py37"
5+
PYTEST_NO_COVERAGE: "1"
6+
- TOXENV: "linting,docs,doctesting"
7+
- TOXENV: "py36"
8+
- TOXENV: "py35"
9+
- TOXENV: "py34"
1010
- TOXENV: "pypy"
1111
PYTEST_NO_COVERAGE: "1"
12-
- TOXENV: "py27-xdist"
13-
- TOXENV: "py27-trial"
14-
- TOXENV: "py27-numpy"
12+
# Specialized factors for py27.
13+
- TOXENV: "py27-trial,py27-numpy,py27-nobyte"
1514
- TOXENV: "py27-pluggymaster"
1615
PYTEST_NO_COVERAGE: "1"
17-
- TOXENV: "py36-xdist"
18-
- TOXENV: "py36-trial"
19-
- TOXENV: "py36-numpy"
16+
- TOXENV: "py27-xdist"
17+
# Specialized factors for py36.
18+
- TOXENV: "py36-trial,py36-numpy"
2019
- TOXENV: "py36-pluggymaster"
2120
PYTEST_NO_COVERAGE: "1"
22-
- TOXENV: "py27-nobyte"
2321
- TOXENV: "py36-freeze"
2422
PYTEST_NO_COVERAGE: "1"
23+
- TOXENV: "py36-xdist"
24+
25+
matrix:
26+
fast_finish: true
2527

2628
install:
2729
- echo Installed Pythons

changelog/4063.trivial.rst

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Exclude 0.00 second entries from ``--duration`` output unless ``-vv`` is passed on the command-line.

changelog/4132.bugfix.rst

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix duplicate printing of internal errors when using ``--pdb``.

changelog/4151.doc.rst

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add tempir testing example to CONTRIBUTING.rst guide

changelog/4152.bugfix.rst

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Display the filename when encountering ``SyntaxWarning``.

doc/en/deprecations.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ This form of test function doesn't support fixtures properly, and users should s
304304
.. code-block:: python
305305
306306
@pytest.mark.parametrize("x, y", [(2, 4), (3, 9)])
307-
def test_squared():
307+
def test_squared(x, y):
308308
assert x ** x == y
309309
310310

doc/en/usage.rst

+1
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ To get a list of the slowest 10 test durations::
269269

270270
pytest --durations=10
271271

272+
By default, pytest will not show test durations that are too small (<0.01s) unless ``-vv`` is passed on the command-line.
272273

273274
Creating JUnitXML format files
274275
----------------------------------------------------

src/_pytest/assertion/rewrite.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ def _rewrite_test(config, fn):
399399
finally:
400400
del state._indecode
401401
try:
402-
tree = ast.parse(source)
402+
tree = ast.parse(source, filename=fn.strpath)
403403
except SyntaxError:
404404
# Let this pop up again in the real import.
405405
state.trace("failed to parse: %r" % (fn,))

src/_pytest/debugging.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
""" interactive debugging with PDB, the Python Debugger. """
22
from __future__ import absolute_import, division, print_function
3+
4+
import os
35
import pdb
46
import sys
5-
import os
67
from doctest import UnexpectedException
78

9+
from _pytest import outcomes
810
from _pytest.config import hookimpl
911

1012
try:
@@ -109,9 +111,6 @@ def pytest_exception_interact(self, node, call, report):
109111
_enter_pdb(node, call.excinfo, report)
110112

111113
def pytest_internalerror(self, excrepr, excinfo):
112-
for line in str(excrepr).split("\n"):
113-
sys.stderr.write("INTERNALERROR> %s\n" % line)
114-
sys.stderr.flush()
115114
tb = _postmortem_traceback(excinfo)
116115
post_mortem(tb)
117116

@@ -164,8 +163,9 @@ def _enter_pdb(node, excinfo, rep):
164163
rep.toterminal(tw)
165164
tw.sep(">", "entering PDB")
166165
tb = _postmortem_traceback(excinfo)
167-
post_mortem(tb)
168166
rep._pdbshown = True
167+
if post_mortem(tb):
168+
outcomes.exit("Quitting debugger")
169169
return rep
170170

171171

@@ -196,3 +196,4 @@ def get_stack(self, f, t):
196196
p = Pdb()
197197
p.reset()
198198
p.interaction(None, t)
199+
return p.quitting

src/_pytest/fixtures.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -1020,7 +1020,7 @@ class FixtureFunctionMarker(object):
10201020

10211021
def __call__(self, function):
10221022
if isclass(function):
1023-
raise ValueError("class fixtures not supported (may be in the future)")
1023+
raise ValueError("class fixtures not supported (maybe in the future)")
10241024

10251025
if getattr(function, "_pytestfixturefunction", False):
10261026
raise ValueError(
@@ -1371,8 +1371,7 @@ def getfixturedefs(self, argname, nodeid):
13711371
fixturedefs = self._arg2fixturedefs[argname]
13721372
except KeyError:
13731373
return None
1374-
else:
1375-
return tuple(self._matchfactories(fixturedefs, nodeid))
1374+
return tuple(self._matchfactories(fixturedefs, nodeid))
13761375

13771376
def _matchfactories(self, fixturedefs, nodeid):
13781377
for fixturedef in fixturedefs:

src/_pytest/main.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -570,9 +570,7 @@ def _recurse(self, path):
570570
return True
571571

572572
def _tryconvertpyarg(self, x):
573-
"""Convert a dotted module name to path.
574-
575-
"""
573+
"""Convert a dotted module name to path."""
576574
try:
577575
with _patched_find_module():
578576
loader = pkgutil.find_loader(x)
@@ -604,8 +602,7 @@ def _parsearg(self, arg):
604602
raise UsageError(
605603
"file or package not found: " + arg + " (missing __init__.py?)"
606604
)
607-
else:
608-
raise UsageError("file not found: " + arg)
605+
raise UsageError("file not found: " + arg)
609606
parts[0] = path
610607
return parts
611608

src/_pytest/pytester.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
from _pytest.capture import MultiCapture, SysCapture
1919
from _pytest._code import Source
20-
from _pytest.main import Session, EXIT_OK
20+
from _pytest.main import Session, EXIT_INTERRUPTED, EXIT_OK
2121
from _pytest.assertion.rewrite import AssertionRewritingHook
2222
from _pytest.pathlib import Path
2323
from _pytest.compat import safe_str
@@ -857,7 +857,7 @@ class reprec(object):
857857

858858
# typically we reraise keyboard interrupts from the child run
859859
# because it's our user requesting interruption of the testing
860-
if ret == 2 and not kwargs.get("no_reraise_ctrlc"):
860+
if ret == EXIT_INTERRUPTED and not kwargs.get("no_reraise_ctrlc"):
861861
calls = reprec.getcalls("pytest_keyboard_interrupt")
862862
if calls and calls[-1].excinfo.type == KeyboardInterrupt:
863863
raise KeyboardInterrupt()

src/_pytest/runner.py

+5
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ def pytest_addoption(parser):
3030

3131
def pytest_terminal_summary(terminalreporter):
3232
durations = terminalreporter.config.option.durations
33+
verbose = terminalreporter.config.getvalue("verbose")
3334
if durations is None:
3435
return
3536
tr = terminalreporter
@@ -49,6 +50,10 @@ def pytest_terminal_summary(terminalreporter):
4950
dlist = dlist[:durations]
5051

5152
for rep in dlist:
53+
if verbose < 2 and rep.duration < 0.005:
54+
tr.write_line("")
55+
tr.write_line("(0.00 durations hidden. Use -vv to show these durations.)")
56+
break
5257
nodeid = rep.nodeid.replace("::()::", "::")
5358
tr.write_line("%02.2fs %-8s %s" % (rep.duration, rep.when, nodeid))
5459

0 commit comments

Comments
 (0)