Replies: 3 comments 2 replies
-
PyCharm also recognizes |
Beta Was this translation helpful? Give feedback.
-
I figured out how to achieve this without modifying the pytest codebase. class NewTerminalReporter(TerminalReporter):
def _locationline(self, nodeid, fspath, lineno, domain):
res = super()._locationline(nodeid, fspath, lineno, domain)
return res.replace("::", ":{}::".format(lineno), 1)
@pytest.hookimpl(trylast=True)
def pytest_configure(config):
old_reporter = config.pluginmanager.getplugin("terminalreporter")
config.pluginmanager.unregister(old_reporter)
new_reporter = NewTerminalReporter(config, sys.stdout)
config.pluginmanager.register(new_reporter, "terminalreporter") |
Beta Was this translation helpful? Give feedback.
-
I got it to work by dropping this into def pytest_runtest_logreport(report: pytest.TestReport):
"""Add line numbers to log report, for easier discovery in code editors."""
# Report location of test (this is NOT the failing line)
report.nodeid = f'{report.location[0]}:{report.location[1]}::{report.location[2]}' The reported line numbers are one less than the actual start of the test definition, usually the preceding blank line, same as what @harupy's screencap shows. It's not clear why, but it's tolerable. When a test fails, I'd like it to report the line number of the failing line so it's easier to jump to, but for that I guess I'll have to examine the traceback and confirm the filename is the same as the test file… |
Beta Was this translation helpful? Give feedback.
-
I think it'd be useful if file path was suffixed with line number (I captured the GIF attached in VSCode). This allows us to jump to test functions easily.
My fork branch containing a patch that enables this feature: https://github.com/harupy/pytest/tree/show-lineno
Beta Was this translation helpful? Give feedback.
All reactions