~ibmcharmers/charms/xenial/ibm-cinder-storwize-svc/trunk

« back to all changes in this revision

Viewing changes to .tox/py35/lib/python3.5/site-packages/_pytest/helpconfig.py

  • Committer: Ankammarao
  • Date: 2017-03-06 05:11:42 UTC
  • Revision ID: achittet@in.ibm.com-20170306051142-dpg27z4es1k56hfn
Marked tests folder executable

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
""" version info, help messages, tracing configuration.  """
 
2
import py
 
3
import pytest
 
4
import os, sys
 
5
 
 
6
def pytest_addoption(parser):
 
7
    group = parser.getgroup('debugconfig')
 
8
    group.addoption('--version', action="store_true",
 
9
            help="display pytest lib version and import information.")
 
10
    group._addoption("-h", "--help", action="store_true", dest="help",
 
11
            help="show help message and configuration info")
 
12
    group._addoption('-p', action="append", dest="plugins", default = [],
 
13
               metavar="name",
 
14
               help="early-load given plugin (multi-allowed). "
 
15
                    "To avoid loading of plugins, use the `no:` prefix, e.g. "
 
16
                    "`no:doctest`.")
 
17
    group.addoption('--traceconfig', '--trace-config',
 
18
               action="store_true", default=False,
 
19
               help="trace considerations of conftest.py files."),
 
20
    group.addoption('--debug',
 
21
               action="store_true", dest="debug", default=False,
 
22
               help="store internal tracing debug information in 'pytestdebug.log'.")
 
23
    group._addoption(
 
24
        '-o', '--override-ini', nargs='*', dest="override_ini",
 
25
        action="append",
 
26
        help="override config option with option=value style, e.g. `-o xfail_strict=True`.")
 
27
 
 
28
 
 
29
@pytest.hookimpl(hookwrapper=True)
 
30
def pytest_cmdline_parse():
 
31
    outcome = yield
 
32
    config = outcome.get_result()
 
33
    if config.option.debug:
 
34
        path = os.path.abspath("pytestdebug.log")
 
35
        debugfile = open(path, 'w')
 
36
        debugfile.write("versions pytest-%s, py-%s, "
 
37
                "python-%s\ncwd=%s\nargs=%s\n\n" %(
 
38
            pytest.__version__, py.__version__,
 
39
            ".".join(map(str, sys.version_info)),
 
40
            os.getcwd(), config._origargs))
 
41
        config.trace.root.setwriter(debugfile.write)
 
42
        undo_tracing = config.pluginmanager.enable_tracing()
 
43
        sys.stderr.write("writing pytestdebug information to %s\n" % path)
 
44
 
 
45
        def unset_tracing():
 
46
            debugfile.close()
 
47
            sys.stderr.write("wrote pytestdebug information to %s\n" %
 
48
                             debugfile.name)
 
49
            config.trace.root.setwriter(None)
 
50
            undo_tracing()
 
51
 
 
52
        config.add_cleanup(unset_tracing)
 
53
 
 
54
def pytest_cmdline_main(config):
 
55
    if config.option.version:
 
56
        p = py.path.local(pytest.__file__)
 
57
        sys.stderr.write("This is pytest version %s, imported from %s\n" %
 
58
            (pytest.__version__, p))
 
59
        plugininfo = getpluginversioninfo(config)
 
60
        if plugininfo:
 
61
            for line in plugininfo:
 
62
                sys.stderr.write(line + "\n")
 
63
        return 0
 
64
    elif config.option.help:
 
65
        config._do_configure()
 
66
        showhelp(config)
 
67
        config._ensure_unconfigure()
 
68
        return 0
 
69
 
 
70
def showhelp(config):
 
71
    reporter = config.pluginmanager.get_plugin('terminalreporter')
 
72
    tw = reporter._tw
 
73
    tw.write(config._parser.optparser.format_help())
 
74
    tw.line()
 
75
    tw.line()
 
76
    tw.line("[pytest] ini-options in the first "
 
77
            "pytest.ini|tox.ini|setup.cfg file found:")
 
78
    tw.line()
 
79
 
 
80
    for name in config._parser._ininames:
 
81
        help, type, default = config._parser._inidict[name]
 
82
        if type is None:
 
83
            type = "string"
 
84
        spec = "%s (%s)" % (name, type)
 
85
        line = "  %-24s %s" %(spec, help)
 
86
        tw.line(line[:tw.fullwidth])
 
87
 
 
88
    tw.line()
 
89
    tw.line("environment variables:")
 
90
    vars = [
 
91
        ("PYTEST_ADDOPTS", "extra command line options"),
 
92
        ("PYTEST_PLUGINS", "comma-separated plugins to load during startup"),
 
93
        ("PYTEST_DEBUG", "set to enable debug tracing of pytest's internals")
 
94
    ]
 
95
    for name, help in vars:
 
96
        tw.line("  %-24s %s" % (name, help))
 
97
    tw.line()
 
98
    tw.line()
 
99
 
 
100
    tw.line("to see available markers type: pytest --markers")
 
101
    tw.line("to see available fixtures type: pytest --fixtures")
 
102
    tw.line("(shown according to specified file_or_dir or current dir "
 
103
            "if not specified)")
 
104
 
 
105
    for warningreport in reporter.stats.get('warnings', []):
 
106
        tw.line("warning : " + warningreport.message, red=True)
 
107
    return
 
108
 
 
109
 
 
110
conftest_options = [
 
111
    ('pytest_plugins', 'list of plugin names to load'),
 
112
]
 
113
 
 
114
def getpluginversioninfo(config):
 
115
    lines = []
 
116
    plugininfo = config.pluginmanager.list_plugin_distinfo()
 
117
    if plugininfo:
 
118
        lines.append("setuptools registered plugins:")
 
119
        for plugin, dist in plugininfo:
 
120
            loc = getattr(plugin, '__file__', repr(plugin))
 
121
            content = "%s-%s at %s" % (dist.project_name, dist.version, loc)
 
122
            lines.append("  " + content)
 
123
    return lines
 
124
 
 
125
def pytest_report_header(config):
 
126
    lines = []
 
127
    if config.option.debug or config.option.traceconfig:
 
128
        lines.append("using: pytest-%s pylib-%s" %
 
129
            (pytest.__version__,py.__version__))
 
130
 
 
131
        verinfo = getpluginversioninfo(config)
 
132
        if verinfo:
 
133
            lines.extend(verinfo)
 
134
 
 
135
    if config.option.traceconfig:
 
136
        lines.append("active plugins:")
 
137
        items = config.pluginmanager.list_name_plugin()
 
138
        for name, plugin in items:
 
139
            if hasattr(plugin, '__file__'):
 
140
                r = plugin.__file__
 
141
            else:
 
142
                r = repr(plugin)
 
143
            lines.append("    %-20s: %s" %(name, r))
 
144
    return lines