Making --debug more configurable for the pytest user (#8955)
Close #8954
This commit is contained in:
@@ -80,10 +80,14 @@ def pytest_addoption(parser: Parser) -> None:
|
||||
)
|
||||
group.addoption(
|
||||
"--debug",
|
||||
action="store_true",
|
||||
action="store",
|
||||
nargs="?",
|
||||
const="pytestdebug.log",
|
||||
dest="debug",
|
||||
default=False,
|
||||
help="store internal tracing debug information in 'pytestdebug.log'.",
|
||||
metavar="DEBUG_FILE_NAME",
|
||||
help="store internal tracing debug information in this log file.\n"
|
||||
"This file is opened with 'w' and truncated as a result, care advised.\n"
|
||||
"Defaults to 'pytestdebug.log'.",
|
||||
)
|
||||
group._addoption(
|
||||
"-o",
|
||||
@@ -98,8 +102,10 @@ def pytest_addoption(parser: Parser) -> None:
|
||||
def pytest_cmdline_parse():
|
||||
outcome = yield
|
||||
config: Config = outcome.get_result()
|
||||
|
||||
if config.option.debug:
|
||||
path = os.path.abspath("pytestdebug.log")
|
||||
# --debug | --debug <file.log> was provided.
|
||||
path = config.option.debug
|
||||
debugfile = open(path, "w")
|
||||
debugfile.write(
|
||||
"versions pytest-%s, py-%s, "
|
||||
@@ -114,11 +120,11 @@ def pytest_cmdline_parse():
|
||||
)
|
||||
config.trace.root.setwriter(debugfile.write)
|
||||
undo_tracing = config.pluginmanager.enable_tracing()
|
||||
sys.stderr.write("writing pytestdebug information to %s\n" % path)
|
||||
sys.stderr.write("writing pytest debug information to %s\n" % path)
|
||||
|
||||
def unset_tracing() -> None:
|
||||
debugfile.close()
|
||||
sys.stderr.write("wrote pytestdebug information to %s\n" % debugfile.name)
|
||||
sys.stderr.write("wrote pytest debug information to %s\n" % debugfile.name)
|
||||
config.trace.root.setwriter(None)
|
||||
undo_tracing()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user