aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/python/pytest/py2/_pytest/setuponly.py
diff options
context:
space:
mode:
authordeshevoy <deshevoy@yandex-team.ru>2022-02-10 16:46:56 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:46:56 +0300
commite988f30484abe5fdeedcc7a5d3c226c01a21800c (patch)
tree0a217b173aabb57b7e51f8a169989b1a3e0309fe /contrib/python/pytest/py2/_pytest/setuponly.py
parent33ee501c05d3f24036ae89766a858930ae66c548 (diff)
downloadydb-e988f30484abe5fdeedcc7a5d3c226c01a21800c.tar.gz
Restoring authorship annotation for <deshevoy@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'contrib/python/pytest/py2/_pytest/setuponly.py')
-rw-r--r--contrib/python/pytest/py2/_pytest/setuponly.py176
1 files changed, 88 insertions, 88 deletions
diff --git a/contrib/python/pytest/py2/_pytest/setuponly.py b/contrib/python/pytest/py2/_pytest/setuponly.py
index 0859011241..ee02bc0ceb 100644
--- a/contrib/python/pytest/py2/_pytest/setuponly.py
+++ b/contrib/python/pytest/py2/_pytest/setuponly.py
@@ -1,89 +1,89 @@
# -*- coding: utf-8 -*-
-from __future__ import absolute_import
-from __future__ import division
-from __future__ import print_function
-
-import sys
-
-import pytest
-
-
-def pytest_addoption(parser):
- group = parser.getgroup("debugconfig")
- group.addoption(
- "--setuponly",
- "--setup-only",
- action="store_true",
- help="only setup fixtures, do not execute tests.",
- )
- group.addoption(
- "--setupshow",
- "--setup-show",
- action="store_true",
- help="show setup of fixtures while executing tests.",
- )
-
-
-@pytest.hookimpl(hookwrapper=True)
-def pytest_fixture_setup(fixturedef, request):
- yield
- config = request.config
- if config.option.setupshow:
- if hasattr(request, "param"):
- # Save the fixture parameter so ._show_fixture_action() can
- # display it now and during the teardown (in .finish()).
- if fixturedef.ids:
- if callable(fixturedef.ids):
- fixturedef.cached_param = fixturedef.ids(request.param)
- else:
- fixturedef.cached_param = fixturedef.ids[request.param_index]
- else:
- fixturedef.cached_param = request.param
- _show_fixture_action(fixturedef, "SETUP")
-
-
-def pytest_fixture_post_finalizer(fixturedef):
- if hasattr(fixturedef, "cached_result"):
- config = fixturedef._fixturemanager.config
- if config.option.setupshow:
- _show_fixture_action(fixturedef, "TEARDOWN")
- if hasattr(fixturedef, "cached_param"):
- del fixturedef.cached_param
-
-
-def _show_fixture_action(fixturedef, msg):
- config = fixturedef._fixturemanager.config
- capman = config.pluginmanager.getplugin("capturemanager")
- if capman:
- capman.suspend_global_capture()
- out, err = capman.read_global_capture()
-
- tw = config.get_terminal_writer()
- tw.line()
- tw.write(" " * 2 * fixturedef.scopenum)
- tw.write(
- "{step} {scope} {fixture}".format(
- step=msg.ljust(8), # align the output to TEARDOWN
- scope=fixturedef.scope[0].upper(),
- fixture=fixturedef.argname,
- )
- )
-
- if msg == "SETUP":
- deps = sorted(arg for arg in fixturedef.argnames if arg != "request")
- if deps:
- tw.write(" (fixtures used: {})".format(", ".join(deps)))
-
- if hasattr(fixturedef, "cached_param"):
- tw.write("[{}]".format(fixturedef.cached_param))
-
- if capman:
- capman.resume_global_capture()
- sys.stdout.write(out)
- sys.stderr.write(err)
-
-
-@pytest.hookimpl(tryfirst=True)
-def pytest_cmdline_main(config):
- if config.option.setuponly:
- config.option.setupshow = True
+from __future__ import absolute_import
+from __future__ import division
+from __future__ import print_function
+
+import sys
+
+import pytest
+
+
+def pytest_addoption(parser):
+ group = parser.getgroup("debugconfig")
+ group.addoption(
+ "--setuponly",
+ "--setup-only",
+ action="store_true",
+ help="only setup fixtures, do not execute tests.",
+ )
+ group.addoption(
+ "--setupshow",
+ "--setup-show",
+ action="store_true",
+ help="show setup of fixtures while executing tests.",
+ )
+
+
+@pytest.hookimpl(hookwrapper=True)
+def pytest_fixture_setup(fixturedef, request):
+ yield
+ config = request.config
+ if config.option.setupshow:
+ if hasattr(request, "param"):
+ # Save the fixture parameter so ._show_fixture_action() can
+ # display it now and during the teardown (in .finish()).
+ if fixturedef.ids:
+ if callable(fixturedef.ids):
+ fixturedef.cached_param = fixturedef.ids(request.param)
+ else:
+ fixturedef.cached_param = fixturedef.ids[request.param_index]
+ else:
+ fixturedef.cached_param = request.param
+ _show_fixture_action(fixturedef, "SETUP")
+
+
+def pytest_fixture_post_finalizer(fixturedef):
+ if hasattr(fixturedef, "cached_result"):
+ config = fixturedef._fixturemanager.config
+ if config.option.setupshow:
+ _show_fixture_action(fixturedef, "TEARDOWN")
+ if hasattr(fixturedef, "cached_param"):
+ del fixturedef.cached_param
+
+
+def _show_fixture_action(fixturedef, msg):
+ config = fixturedef._fixturemanager.config
+ capman = config.pluginmanager.getplugin("capturemanager")
+ if capman:
+ capman.suspend_global_capture()
+ out, err = capman.read_global_capture()
+
+ tw = config.get_terminal_writer()
+ tw.line()
+ tw.write(" " * 2 * fixturedef.scopenum)
+ tw.write(
+ "{step} {scope} {fixture}".format(
+ step=msg.ljust(8), # align the output to TEARDOWN
+ scope=fixturedef.scope[0].upper(),
+ fixture=fixturedef.argname,
+ )
+ )
+
+ if msg == "SETUP":
+ deps = sorted(arg for arg in fixturedef.argnames if arg != "request")
+ if deps:
+ tw.write(" (fixtures used: {})".format(", ".join(deps)))
+
+ if hasattr(fixturedef, "cached_param"):
+ tw.write("[{}]".format(fixturedef.cached_param))
+
+ if capman:
+ capman.resume_global_capture()
+ sys.stdout.write(out)
+ sys.stderr.write(err)
+
+
+@pytest.hookimpl(tryfirst=True)
+def pytest_cmdline_main(config):
+ if config.option.setuponly:
+ config.option.setupshow = True