Skip to content

Commit c2864ab

Browse files
committed
Merge branch 'master' into merge-master
# Conflicts: # AUTHORS # CHANGELOG.rst # _pytest/monkeypatch.py # _pytest/python.py
2 parents 9cf09cd + d911bfc commit c2864ab

18 files changed

+216
-50
lines changed

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ Thanks for submitting a PR, your contribution is really appreciated!
22

33
Here's a quick checklist that should be present in PRs:
44

5-
- [ ] Target: for bug or doc fixes, target `master`; for new features, target `features`
6-
- [ ] Make sure to include one or more tests for your change
7-
- [ ] Add yourself to `AUTHORS`
8-
- [ ] Add a new entry to the `CHANGELOG` (choose any open position to avoid merge conflicts with other PRs)
5+
- [ ] Target: for bug or doc fixes, target `master`; for new features, target `features`;
6+
- [ ] Make sure to include one or more tests for your change;
7+
- [ ] Add yourself to `AUTHORS`;
8+
- [ ] Add a new entry to `CHANGELOG.rst`
9+
* Choose any open position to avoid merge conflicts with other PRs.
10+
* Add a link to the issue you are fixing (if any) using RST syntax.
11+
* The pytest team likes to have people to acknowledged in the `CHANGELOG`, so please add a thank note to yourself ("Thanks @user for the PR") and a link to your GitHub profile. It may sound weird thanking yourself, but otherwise a maintainer would have to do it manually before or after merging instead of just using GitHub's merge button. This makes it easier on the maintainers to merge PRs.

AUTHORS

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,16 @@ Abhijeet Kasurde
88
Alexei Kozlenok
99
Anatoly Bubenkoff
1010
Andreas Zeidler
11-
Andy Freeland
1211
Andrzej Ostrowski
12+
Andy Freeland
1313
Anthon van der Neut
1414
Antony Lee
1515
Armin Rigo
1616
Aron Curzon
1717
Aviv Palivoda
1818
Ben Webb
1919
Benjamin Peterson
20+
Bernard Pratz
2021
Bob Ippolito
2122
Brian Dorsey
2223
Brian Okken
@@ -38,7 +39,10 @@ Dave Hunt
3839
David Díaz-Barquero
3940
David Mohr
4041
David Vierra
42+
Diego Russo
43+
Dmitry Dygalo
4144
Edison Gustavo Muenz
45+
Edoardo Batini
4246
Eduardo Schettino
4347
Elizaveta Shashkova
4448
Endre Galaczi
@@ -62,12 +66,14 @@ Jan Balster
6266
Janne Vanhala
6367
Jason R. Coombs
6468
Javier Domingo Cansino
69+
Javier Romero
6570
John Towler
71+
Jon Sonesen
6672
Joshua Bronson
6773
Jurko Gospodnetić
6874
Justyna Janczyszyn
69-
Katarzyna Jachim
7075
Kale Kundert
76+
Katarzyna Jachim
7177
Kevin Cox
7278
Lee Kamentsky
7379
Lukas Bednar
@@ -77,8 +83,8 @@ Marc Schlaich
7783
Mark Abramowitz
7884
Markus Unterwaditzer
7985
Martijn Faassen
80-
Martin Prusse
8186
Martin K. Scherer
87+
Martin Prusse
8288
Matt Bachmann
8389
Matt Williams
8490
Michael Aquilina
@@ -103,17 +109,17 @@ Ross Lawley
103109
Russel Winder
104110
Ryan Wooden
105111
Samuele Pedroni
112+
Simon Gomizelj
113+
Stefan Farmbauer
114+
Stefan Zimmermann
115+
Stefano Taschini
106116
Steffen Allner
107117
Stephan Obermann
108118
Tareq Alayan
109119
Ted Xiao
110-
Simon Gomizelj
111-
Stefano Taschini
112-
Stefan Farmbauer
113120
Thomas Grainger
114121
Tom Viner
115122
Trevor Bekolay
116123
Vasily Kuznetsov
117124
Wouter van Ackooy
118-
Bernard Pratz
119-
Stefan Zimmermann
125+

CHANGELOG.rst

Lines changed: 49 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,12 @@ time or change existing behaviors in order to make them less surprising/more use
229229
removed in pytest-4.0 (`#1684`_).
230230
Thanks `@nicoddemus`_ for the PR.
231231

232+
* Raise helpful failure message, when requesting parametrized fixture at runtime,
233+
e.g. with ``request.getfuncargvalue``. BACKWARD INCOMPAT: Previously these params
234+
were simply never defined. So a fixture decorated like ``@pytest.fixture(params=[0, 1, 2])``
235+
only ran once. Now a failure is raised. Fixes (`#460`_). Thanks to
236+
`@nikratio`_ for bug report, `@RedBeardCode`_ and `@tomviner`_ for the PR.
237+
232238
* Passing a command-line string to ``pytest.main()`` is considered deprecated and scheduled
233239
for removal in pytest-4.0. It is recommended to pass a list of arguments instead (`#1723`_).
234240

@@ -238,12 +244,19 @@ time or change existing behaviors in order to make them less surprising/more use
238244

239245
* ``optparse`` type usage now triggers DeprecationWarnings (`#1740`_).
240246

247+
241248
* ``optparse`` backward compatibility supports float/complex types (`#457`_).
242249

250+
* Renamed the pytest ``pdb`` module (plugin) into ``debugging``.
251+
243252
* Better message in case of not using parametrized variable (see `#1539`_).
244253
Thanks to `@tramwaj29`_ for the PR.
245254

246-
*
255+
* Updated docstrings with a more uniform style.
256+
257+
* Add stderr write for ``pytest.exit(msg)`` during startup. Previously the message was never shown.
258+
Thanks `@BeyondEvil`_ for reporting `#1210`_. Thanks to `@JonathonSonesen`_ and
259+
`@tomviner`_ for PR.
247260

248261
*
249262

@@ -271,7 +284,18 @@ time or change existing behaviors in order to make them less surprising/more use
271284
identify bugs in ``conftest.py`` files (`#1516`_). Thanks `@txomon`_ for
272285
the PR.
273286

274-
*
287+
* Add an 'E' to the first line of error messages from FixtureLookupErrorRepr.
288+
Fixes `#717`_. Thanks `@blueyed`_ for reporting, `@eolo999`_ for the PR
289+
and `@tomviner`_ for his guidance during EuroPython2016 sprint.
290+
291+
* Text documents without any doctests no longer appear as "skipped".
292+
Thanks `@graingert`_ for reporting and providing a full PR (`#1580`_).
293+
294+
* Fixed collection of classes with custom ``__new__`` method.
295+
Fixes `#1579`_. Thanks to `@Stranger6667`_ for the PR.
296+
297+
* Fixed scope overriding inside metafunc.parametrize (`#634`_).
298+
Thanks to `@Stranger6667`_ for the PR.
275299

276300
*
277301

@@ -281,12 +305,7 @@ time or change existing behaviors in order to make them less surprising/more use
281305

282306
*
283307

284-
.. _#372: https://github.com/pytest-dev/pytest/issues/372
285-
.. _#460: https://github.com/pytest-dev/pytest/pull/460
286-
.. _#457: https://github.com/pytest-dev/pytest/issues/457
287-
.. _#1740: https://github.com/pytest-dev/pytest/issues/1740
288-
.. _#607: https://github.com/pytest-dev/pytest/issues/607
289-
.. _#925: https://github.com/pytest-dev/pytest/issues/925
308+
.. _#1210: https://github.com/pytest-dev/pytest/issues/1210
290309
.. _#1235: https://github.com/pytest-dev/pytest/issues/1235
291310
.. _#1351: https://github.com/pytest-dev/pytest/issues/1351
292311
.. _#1421: https://github.com/pytest-dev/pytest/issues/1421
@@ -305,42 +324,52 @@ time or change existing behaviors in order to make them less surprising/more use
305324
.. _#1519: https://github.com/pytest-dev/pytest/pull/1519
306325
.. _#1520: https://github.com/pytest-dev/pytest/pull/1520
307326
.. _#1526: https://github.com/pytest-dev/pytest/pull/1526
327+
.. _#1539: https://github.com/pytest-dev/pytest/issues/1539
308328
.. _#1544: https://github.com/pytest-dev/pytest/issues/1544
309329
.. _#1553: https://github.com/pytest-dev/pytest/issues/1553
310330
.. _#1562: https://github.com/pytest-dev/pytest/issues/1562
331+
.. _#1579: https://github.com/pytest-dev/pytest/issues/1579
311332
.. _#1580: https://github.com/pytest-dev/pytest/pull/1580
312333
.. _#1597: https://github.com/pytest-dev/pytest/pull/1597
313334
.. _#1605: https://github.com/pytest-dev/pytest/issues/1605
314335
.. _#1616: https://github.com/pytest-dev/pytest/pull/1616
315336
.. _#1618: https://github.com/pytest-dev/pytest/issues/1618
316337
.. _#1619: https://github.com/pytest-dev/pytest/issues/1619
317338
.. _#1626: https://github.com/pytest-dev/pytest/pull/1626
318-
.. _#1668: https://github.com/pytest-dev/pytest/issues/1668
319339
.. _#1627: https://github.com/pytest-dev/pytest/pull/1627
320340
.. _#1628: https://github.com/pytest-dev/pytest/pull/1628
321341
.. _#1629: https://github.com/pytest-dev/pytest/issues/1629
322342
.. _#1632: https://github.com/pytest-dev/pytest/issues/1632
323343
.. _#1633: https://github.com/pytest-dev/pytest/pull/1633
324344
.. _#1664: https://github.com/pytest-dev/pytest/pull/1664
345+
.. _#1668: https://github.com/pytest-dev/pytest/issues/1668
325346
.. _#1684: https://github.com/pytest-dev/pytest/pull/1684
326347
.. _#1723: https://github.com/pytest-dev/pytest/pull/1723
327-
.. _#1539: https://github.com/pytest-dev/pytest/issues/1539
348+
.. _#1740: https://github.com/pytest-dev/pytest/issues/1740
328349
.. _#1749: https://github.com/pytest-dev/pytest/issues/1749
350+
.. _#372: https://github.com/pytest-dev/pytest/issues/372
351+
.. _#457: https://github.com/pytest-dev/pytest/issues/457
352+
.. _#460: https://github.com/pytest-dev/pytest/pull/460
353+
.. _#607: https://github.com/pytest-dev/pytest/issues/607
354+
.. _#634: https://github.com/pytest-dev/pytest/issues/634
355+
.. _#717: https://github.com/pytest-dev/pytest/issues/717
356+
.. _#925: https://github.com/pytest-dev/pytest/issues/925
329357

330-
.. _@DRMacIver: https://github.com/DRMacIver
331-
.. _@RedBeardCode: https://github.com/RedBeardCode
332-
.. _@Vogtinator: https://github.com/Vogtinator
333358
.. _@anntzer: https://github.com/anntzer
334359
.. _@bagerard: https://github.com/bagerard
360+
.. _@BeyondEvil: https://github.com/BeyondEvil
335361
.. _@blueyed: https://github.com/blueyed
336362
.. _@ceridwen: https://github.com/ceridwen
337363
.. _@csaftoiu: https://github.com/csaftoiu
338364
.. _@d6e: https://github.com/d6e
339365
.. _@davehunt: https://github.com/davehunt
366+
.. _@DRMacIver: https://github.com/DRMacIver
367+
.. _@eolo999: https://github.com/eolo999
340368
.. _@fengxx: https://github.com/fengxx
341369
.. _@flub: https://github.com/flub
342370
.. _@graingert: https://github.com/graingert
343371
.. _@hartym: https://github.com/hartym
372+
.. _@JonathonSonesen: https://github.com/JonathonSonesen
344373
.. _@kalekundert: https://github.com/kalekundert
345374
.. _@kvas-it: https://github.com/kvas-it
346375
.. _@marscher: https://github.com/marscher
@@ -353,12 +382,16 @@ time or change existing behaviors in order to make them less surprising/more use
353382
.. _@olegpidsadnyi: https://github.com/olegpidsadnyi
354383
.. _@omarkohl: https://github.com/omarkohl
355384
.. _@palaviv: https://github.com/palaviv
385+
.. _@RedBeardCode: https://github.com/RedBeardCode
356386
.. _@sallner: https://github.com/sallner
357387
.. _@sober7: https://github.com/sober7
388+
.. _@Stranger6667: https://github.com/Stranger6667
358389
.. _@tareqalayan: https://github.com/tareqalayan
359390
.. _@taschini: https://github.com/taschini
360-
.. _@txomon: https://github.com/txomon
361391
.. _@tramwaj29: https://github.com/tramwaj29
392+
.. _@txomon: https://github.com/txomon
393+
.. _@Vogtinator: https://github.com/Vogtinator
394+
362395

363396
2.9.2
364397
=====
@@ -392,8 +425,8 @@ time or change existing behaviors in order to make them less surprising/more use
392425

393426
.. _#510: https://github.com/pytest-dev/pytest/issues/510
394427
.. _#1506: https://github.com/pytest-dev/pytest/pull/1506
395-
.. _#1496: https://github.com/pytest-dev/pytest/issue/1496
396-
.. _#1524: https://github.com/pytest-dev/pytest/issue/1524
428+
.. _#1496: https://github.com/pytest-dev/pytest/issues/1496
429+
.. _#1524: https://github.com/pytest-dev/pytest/pull/1524
397430

398431
.. _@prusse-martin: https://github.com/prusse-martin
399432
.. _@astraw38: https://github.com/astraw38

_pytest/capture.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ def suspendcapture_item(self, item, when, in_=False):
157157

158158
@pytest.fixture
159159
def capsys(request):
160-
"""enables capturing of writes to sys.stdout/sys.stderr and makes
160+
"""Enable capturing of writes to sys.stdout/sys.stderr and make
161161
captured output available via ``capsys.readouterr()`` method calls
162162
which return a ``(out, err)`` tuple.
163163
"""
@@ -168,7 +168,7 @@ def capsys(request):
168168

169169
@pytest.fixture
170170
def capfd(request):
171-
"""enables capturing of writes to file descriptors 1 and 2 and makes
171+
"""Enable capturing of writes to file descriptors 1 and 2 and make
172172
captured output available via ``capfd.readouterr()`` method calls
173173
which return a ``(out, err)`` tuple.
174174
"""

_pytest/fixtures.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -673,8 +673,13 @@ def toterminal(self, tw):
673673
#tw.line("FixtureLookupError: %s" %(self.argname), red=True)
674674
for tbline in self.tblines:
675675
tw.line(tbline.rstrip())
676-
for line in self.errorstring.split("\n"):
677-
tw.line(" " + line.strip(), red=True)
676+
lines = self.errorstring.split("\n")
677+
for line in lines:
678+
if line == lines[0]:
679+
prefix = 'E '
680+
else:
681+
prefix = ' '
682+
tw.line(prefix + line.strip(), red=True)
678683
tw.line()
679684
tw.line("%s:%d" % (self.filename, self.firstlineno+1))
680685

_pytest/junitxml.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,8 @@ def finalize(self):
186186

187187
@pytest.fixture
188188
def record_xml_property(request):
189-
"""Fixture that adds extra xml properties to the tag for the calling test.
190-
The fixture is callable with (name, value), with value being automatically
189+
"""Add extra xml properties to the tag for the calling test.
190+
The fixture is callable with ``(name, value)``, with value being automatically
191191
xml-encoded.
192192
"""
193193
request.node.warn(

_pytest/main.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ def wrap_session(config, doit):
9898
raise
9999
except KeyboardInterrupt:
100100
excinfo = _pytest._code.ExceptionInfo()
101+
if initstate < 2 and isinstance(
102+
excinfo.value, pytest.exit.Exception):
103+
sys.stderr.write('{0}: {1}\n'.format(
104+
excinfo.typename, excinfo.value.msg))
101105
config.hook.pytest_keyboard_interrupt(excinfo=excinfo)
102106
session.exitstatus = EXIT_INTERRUPTED
103107
except:

_pytest/monkeypatch.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,10 +226,10 @@ def undo(self):
226226
""" Undo previous changes. This call consumes the
227227
undo stack. Calling it a second time has no effect unless
228228
you do more monkeypatching after the undo call.
229-
229+
230230
There is generally no need to call `undo()`, since it is
231231
called automatically during tear-down.
232-
232+
233233
Note that the same `monkeypatch` fixture is used across a
234234
single test function invocation. If `monkeypatch` is used both by
235235
the test function itself and one of the test fixtures,

_pytest/python.py

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,10 @@ def collect(self):
489489
self.warn("C1", "cannot collect test class %r because it has a "
490490
"__init__ constructor" % self.obj.__name__)
491491
return []
492+
elif hasnew(self.obj):
493+
self.warn("C1", "cannot collect test class %r because it has a "
494+
"__new__ constructor" % self.obj.__name__)
495+
return []
492496
return [self._getcustomclass("Instance")(name="()", parent=self)]
493497

494498
def setup(self):
@@ -506,8 +510,7 @@ def setup(self):
506510

507511
class Instance(PyCollector):
508512
def _getobj(self):
509-
obj = self.parent.obj()
510-
return obj
513+
return self.parent.obj()
511514

512515
def collect(self):
513516
self.session._fixturemanager.parsefactories(self)
@@ -622,8 +625,13 @@ def getcallargs(self, obj):
622625
def hasinit(obj):
623626
init = getattr(obj, '__init__', None)
624627
if init:
625-
if init != object.__init__:
626-
return True
628+
return init != object.__init__
629+
630+
631+
def hasnew(obj):
632+
new = getattr(obj, '__new__', None)
633+
if new:
634+
return new != object.__new__
627635

628636

629637
class CallSpec2(object):
@@ -763,7 +771,7 @@ def parametrize(self, argnames, argvalues, indirect=False, ids=None,
763771
It will also override any fixture-function defined scope, allowing
764772
to set a dynamic scope using test context or configuration.
765773
"""
766-
774+
from _pytest.fixtures import scopes
767775
# individual parametrized argument sets can be wrapped in a series
768776
# of markers in which case we unwrap the values and apply the mark
769777
# at Function init
@@ -794,10 +802,16 @@ def parametrize(self, argnames, argvalues, indirect=False, ids=None,
794802
newmarks = newkeywords.setdefault(0, {})
795803
newmarks[newmark.markname] = newmark
796804

797-
798805
if scope is None:
799-
scope = "function"
800-
scopenum = fixtures.scopes.index(scope)
806+
if self._arg2fixturedefs:
807+
# Takes the most narrow scope from used fixtures
808+
fixtures_scopes = [fixturedef[0].scope for fixturedef in self._arg2fixturedefs.values()]
809+
for scope in reversed(scopes):
810+
if scope in fixtures_scopes:
811+
break
812+
else:
813+
scope = 'function'
814+
scopenum = scopes.index(scope)
801815
valtypes = {}
802816
for arg in argnames:
803817
if arg not in self.fixturenames:

_pytest/tmpdir.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def tmpdir_factory(request):
108108

109109
@pytest.fixture
110110
def tmpdir(request, tmpdir_factory):
111-
"""return a temporary directory path object
111+
"""Return a temporary directory path object
112112
which is unique to each test function invocation,
113113
created as a sub directory of the base temporary
114114
directory. The returned object is a `py.path.local`_

0 commit comments

Comments
 (0)