Skip to content

Commit d872791

Browse files
authored
Merge pull request #3041 from segevfiner/capture-no-disable-progress
Use classic console output when -s is used
2 parents f8f1a52 + 0a2735a commit d872791

File tree

18 files changed

+322
-76
lines changed

18 files changed

+322
-76
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ Grig Gheorghiu
7474
Grigorii Eremeev (budulianin)
7575
Guido Wesdorp
7676
Harald Armin Massa
77+
Henk-Jaap Wagenaar
7778
Hugo van Kemenade
7879
Hui Wang (coldnight)
7980
Ian Bicking

_pytest/assertion/rewrite.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -179,11 +179,13 @@ def mark_rewrite(self, *names):
179179
The named module or package as well as any nested modules will
180180
be rewritten on import.
181181
"""
182-
already_imported = set(names).intersection(set(sys.modules))
183-
if already_imported:
184-
for name in already_imported:
185-
if name not in self._rewritten_names:
186-
self._warn_already_imported(name)
182+
already_imported = (set(names)
183+
.intersection(sys.modules)
184+
.difference(self._rewritten_names))
185+
for name in already_imported:
186+
if not AssertionRewriter.is_rewrite_disabled(
187+
sys.modules[name].__doc__ or ""):
188+
self._warn_already_imported(name)
187189
self._must_rewrite.update(names)
188190

189191
def _warn_already_imported(self, name):
@@ -635,7 +637,8 @@ def run(self, mod):
635637
not isinstance(field, ast.expr)):
636638
nodes.append(field)
637639

638-
def is_rewrite_disabled(self, docstring):
640+
@staticmethod
641+
def is_rewrite_disabled(docstring):
639642
return "PYTEST_DONT_REWRITE" in docstring
640643

641644
def variable(self):

_pytest/fixtures.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,6 @@ def __init__(self, pyfuncitem):
267267
self.fixturename = None
268268
#: Scope string, one of "function", "class", "module", "session"
269269
self.scope = "function"
270-
self._fixture_values = {} # argname -> fixture value
271270
self._fixture_defs = {} # argname -> FixtureDef
272271
fixtureinfo = pyfuncitem._fixtureinfo
273272
self._arg2fixturedefs = fixtureinfo.name2fixturedefs.copy()
@@ -450,8 +449,7 @@ class PseudoFixtureDef:
450449
raise
451450
# remove indent to prevent the python3 exception
452451
# from leaking into the call
453-
result = self._getfixturevalue(fixturedef)
454-
self._fixture_values[argname] = result
452+
self._compute_fixture_value(fixturedef)
455453
self._fixture_defs[argname] = fixturedef
456454
return fixturedef
457455

@@ -466,7 +464,14 @@ def _get_fixturestack(self):
466464
values.append(fixturedef)
467465
current = current._parent_request
468466

469-
def _getfixturevalue(self, fixturedef):
467+
def _compute_fixture_value(self, fixturedef):
468+
"""
469+
Creates a SubRequest based on "self" and calls the execute method of the given fixturedef object. This will
470+
force the FixtureDef object to throw away any previous results and compute a new fixture value, which
471+
will be stored into the FixtureDef object itself.
472+
473+
:param FixtureDef fixturedef:
474+
"""
470475
# prepare a subrequest object before calling fixture function
471476
# (latter managed by fixturedef)
472477
argname = fixturedef.argname
@@ -515,12 +520,11 @@ def _getfixturevalue(self, fixturedef):
515520
exc_clear()
516521
try:
517522
# call the fixture function
518-
val = fixturedef.execute(request=subrequest)
523+
fixturedef.execute(request=subrequest)
519524
finally:
520525
# if fixture function failed it might have registered finalizers
521526
self.session._setupstate.addfinalizer(functools.partial(fixturedef.finish, request=subrequest),
522527
subrequest.node)
523-
return val
524528

525529
def _check_scope(self, argname, invoking_scope, requested_scope):
526530
if argname == "request":
@@ -573,7 +577,6 @@ def __init__(self, request, scope, param, param_index, fixturedef):
573577
self.scope = scope
574578
self._fixturedef = fixturedef
575579
self._pyfuncitem = request._pyfuncitem
576-
self._fixture_values = request._fixture_values
577580
self._fixture_defs = request._fixture_defs
578581
self._arg2fixturedefs = request._arg2fixturedefs
579582
self._arg2index = request._arg2index

_pytest/hookspec.py

Lines changed: 95 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,31 @@
1212
@hookspec(historic=True)
1313
def pytest_addhooks(pluginmanager):
1414
"""called at plugin registration time to allow adding new hooks via a call to
15-
pluginmanager.add_hookspecs(module_or_class, prefix)."""
15+
``pluginmanager.add_hookspecs(module_or_class, prefix)``.
16+
17+
18+
:param _pytest.config.PytestPluginManager pluginmanager: pytest plugin manager
19+
"""
1620

1721

1822
@hookspec(historic=True)
1923
def pytest_namespace():
2024
"""
21-
DEPRECATED: this hook causes direct monkeypatching on pytest, its use is strongly discouraged
25+
(**Deprecated**) this hook causes direct monkeypatching on pytest, its use is strongly discouraged
2226
return dict of name->object to be made globally available in
23-
the pytest namespace. This hook is called at plugin registration
24-
time.
27+
the pytest namespace.
28+
29+
This hook is called at plugin registration time.
2530
"""
2631

2732

2833
@hookspec(historic=True)
2934
def pytest_plugin_registered(plugin, manager):
30-
""" a new pytest plugin got registered. """
35+
""" a new pytest plugin got registered.
36+
37+
:param plugin: the plugin module or instance
38+
:param _pytest.config.PytestPluginManager manager: pytest plugin manager
39+
"""
3140

3241

3342
@hookspec(historic=True)
@@ -41,7 +50,7 @@ def pytest_addoption(parser):
4150
files situated at the tests root directory due to how pytest
4251
:ref:`discovers plugins during startup <pluginorder>`.
4352
44-
:arg parser: To add command line options, call
53+
:arg _pytest.config.Parser parser: To add command line options, call
4554
:py:func:`parser.addoption(...) <_pytest.config.Parser.addoption>`.
4655
To add ini-file values call :py:func:`parser.addini(...)
4756
<_pytest.config.Parser.addini>`.
@@ -56,8 +65,7 @@ def pytest_addoption(parser):
5665
a value read from an ini-style file.
5766
5867
The config object is passed around on many internal objects via the ``.config``
59-
attribute or can be retrieved as the ``pytestconfig`` fixture or accessed
60-
via (deprecated) ``pytest.config``.
68+
attribute or can be retrieved as the ``pytestconfig`` fixture.
6169
"""
6270

6371

@@ -72,8 +80,7 @@ def pytest_configure(config):
7280
After that, the hook is called for other conftest files as they are
7381
imported.
7482
75-
:arg config: pytest config object
76-
:type config: _pytest.config.Config
83+
:arg _pytest.config.Config config: pytest config object
7784
"""
7885

7986
# -------------------------------------------------------------------------
@@ -87,24 +94,43 @@ def pytest_configure(config):
8794
def pytest_cmdline_parse(pluginmanager, args):
8895
"""return initialized config object, parsing the specified args.
8996
90-
Stops at first non-None result, see :ref:`firstresult` """
97+
Stops at first non-None result, see :ref:`firstresult`
98+
99+
:param _pytest.config.PytestPluginManager pluginmanager: pytest plugin manager
100+
:param list[str] args: list of arguments passed on the command line
101+
"""
91102

92103

93104
def pytest_cmdline_preparse(config, args):
94-
"""(deprecated) modify command line arguments before option parsing. """
105+
"""(**Deprecated**) modify command line arguments before option parsing.
106+
107+
This hook is considered deprecated and will be removed in a future pytest version. Consider
108+
using :func:`pytest_load_initial_conftests` instead.
109+
110+
:param _pytest.config.Config config: pytest config object
111+
:param list[str] args: list of arguments passed on the command line
112+
"""
95113

96114

97115
@hookspec(firstresult=True)
98116
def pytest_cmdline_main(config):
99117
""" called for performing the main command line action. The default
100118
implementation will invoke the configure hooks and runtest_mainloop.
101119
102-
Stops at first non-None result, see :ref:`firstresult` """
120+
Stops at first non-None result, see :ref:`firstresult`
121+
122+
:param _pytest.config.Config config: pytest config object
123+
"""
103124

104125

105126
def pytest_load_initial_conftests(early_config, parser, args):
106127
""" implements the loading of initial conftest files ahead
107-
of command line option parsing. """
128+
of command line option parsing.
129+
130+
:param _pytest.config.Config early_config: pytest config object
131+
:param list[str] args: list of arguments passed on the command line
132+
:param _pytest.config.Parser parser: to add command line options
133+
"""
108134

109135

110136
# -------------------------------------------------------------------------
@@ -113,18 +139,29 @@ def pytest_load_initial_conftests(early_config, parser, args):
113139

114140
@hookspec(firstresult=True)
115141
def pytest_collection(session):
116-
""" perform the collection protocol for the given session.
142+
"""Perform the collection protocol for the given session.
117143
118-
Stops at first non-None result, see :ref:`firstresult` """
144+
Stops at first non-None result, see :ref:`firstresult`.
145+
146+
:param _pytest.main.Session session: the pytest session object
147+
"""
119148

120149

121150
def pytest_collection_modifyitems(session, config, items):
122151
""" called after collection has been performed, may filter or re-order
123-
the items in-place."""
152+
the items in-place.
153+
154+
:param _pytest.main.Session session: the pytest session object
155+
:param _pytest.config.Config config: pytest config object
156+
:param List[_pytest.main.Item] items: list of item objects
157+
"""
124158

125159

126160
def pytest_collection_finish(session):
127-
""" called after collection has been performed and modified. """
161+
""" called after collection has been performed and modified.
162+
163+
:param _pytest.main.Session session: the pytest session object
164+
"""
128165

129166

130167
@hookspec(firstresult=True)
@@ -134,19 +171,28 @@ def pytest_ignore_collect(path, config):
134171
more specific hooks.
135172
136173
Stops at first non-None result, see :ref:`firstresult`
174+
175+
:param str path: the path to analyze
176+
:param _pytest.config.Config config: pytest config object
137177
"""
138178

139179

140180
@hookspec(firstresult=True)
141181
def pytest_collect_directory(path, parent):
142182
""" called before traversing a directory for collection files.
143183
144-
Stops at first non-None result, see :ref:`firstresult` """
184+
Stops at first non-None result, see :ref:`firstresult`
185+
186+
:param str path: the path to analyze
187+
"""
145188

146189

147190
def pytest_collect_file(path, parent):
148191
""" return collection Node or None for the given path. Any new node
149-
needs to have the specified ``parent`` as a parent."""
192+
needs to have the specified ``parent`` as a parent.
193+
194+
:param str path: the path to collect
195+
"""
150196

151197
# logging hooks for collection
152198

@@ -212,7 +258,12 @@ def pytest_make_parametrize_id(config, val, argname):
212258
by @pytest.mark.parametrize calls. Return None if the hook doesn't know about ``val``.
213259
The parameter name is available as ``argname``, if required.
214260
215-
Stops at first non-None result, see :ref:`firstresult` """
261+
Stops at first non-None result, see :ref:`firstresult`
262+
263+
:param _pytest.config.Config config: pytest config object
264+
:param val: the parametrized value
265+
:param str argname: the automatic parameter name produced by pytest
266+
"""
216267

217268
# -------------------------------------------------------------------------
218269
# generic runtest related hooks
@@ -224,11 +275,14 @@ def pytest_runtestloop(session):
224275
""" called for performing the main runtest loop
225276
(after collection finished).
226277
227-
Stops at first non-None result, see :ref:`firstresult` """
278+
Stops at first non-None result, see :ref:`firstresult`
279+
280+
:param _pytest.main.Session session: the pytest session object
281+
"""
228282

229283

230284
def pytest_itemstart(item, node):
231-
""" (deprecated, use pytest_runtest_logstart). """
285+
"""(**Deprecated**) use pytest_runtest_logstart. """
232286

233287

234288
@hookspec(firstresult=True)
@@ -307,15 +361,25 @@ def pytest_fixture_post_finalizer(fixturedef, request):
307361

308362

309363
def pytest_sessionstart(session):
310-
""" before session.main() is called. """
364+
""" before session.main() is called.
365+
366+
:param _pytest.main.Session session: the pytest session object
367+
"""
311368

312369

313370
def pytest_sessionfinish(session, exitstatus):
314-
""" whole test run finishes. """
371+
""" whole test run finishes.
372+
373+
:param _pytest.main.Session session: the pytest session object
374+
:param int exitstatus: the status which pytest will return to the system
375+
"""
315376

316377

317378
def pytest_unconfigure(config):
318-
""" called before test process is exited. """
379+
""" called before test process is exited.
380+
381+
:param _pytest.config.Config config: pytest config object
382+
"""
319383

320384

321385
# -------------------------------------------------------------------------
@@ -329,6 +393,8 @@ def pytest_assertrepr_compare(config, op, left, right):
329393
of strings. The strings will be joined by newlines but any newlines
330394
*in* a string will be escaped. Note that all but the first line will
331395
be indented slightly, the intention is for the first line to be a summary.
396+
397+
:param _pytest.config.Config config: pytest config object
332398
"""
333399

334400
# -------------------------------------------------------------------------
@@ -339,7 +405,7 @@ def pytest_assertrepr_compare(config, op, left, right):
339405
def pytest_report_header(config, startdir):
340406
""" return a string or list of strings to be displayed as header info for terminal reporting.
341407
342-
:param config: the pytest config object.
408+
:param _pytest.config.Config config: pytest config object
343409
:param startdir: py.path object with the starting dir
344410
345411
.. note::
@@ -358,7 +424,7 @@ def pytest_report_collectionfinish(config, startdir, items):
358424
359425
This strings will be displayed after the standard "collected X items" message.
360426
361-
:param config: the pytest config object.
427+
:param _pytest.config.Config config: pytest config object
362428
:param startdir: py.path object with the starting dir
363429
:param items: list of pytest items that are going to be executed; this list should not be modified.
364430
"""
@@ -418,6 +484,5 @@ def pytest_enter_pdb(config):
418484
""" called upon pdb.set_trace(), can be used by plugins to take special
419485
action just before the python debugger enters in interactive mode.
420486
421-
:arg config: pytest config object
422-
:type config: _pytest.config.Config
487+
:param _pytest.config.Config config: pytest config object
423488
"""

0 commit comments

Comments
 (0)