[Pytest-commit] Issue #569: Nicer filenames in terminal reports, custom startdir? (hpk42/pytest)

Ivan Smirnov issues-reply at bitbucket.org
Mon Aug 25 13:22:14 CEST 2014


New issue 569: Nicer filenames in terminal reports, custom startdir?
https://bitbucket.org/hpk42/pytest/issue/569/nicer-filenames-in-terminal-reports-custom

Ivan Smirnov:

When testing an installed package (e.g. as in the example below via `py.test -v --pyargs foo`), the report looks super ugly containing long paths:
```
envs/py27/lib/python2.7/site-packages/foo/tests/test_foo.py::TestBar::test_baz PASSED
envs/py27/lib/python2.7/site-packages/foo/tests/test_bar.py::TestBar::test_baz PASSED
```

It would be sure nice to get something like this:
```
foo/tests/test_foo.py::TestBar::test_baz PASSED
foo/tests/test_bar.py::TestBar::test_baz PASSED
```

Or even this:
```
test_foo.py::TestBar::test_baz PASSED
test_bar.py::TestBar::test_baz PASSED
```
but it would require setting a starting folder manually somehow. I've noticed this code in `TerminalReporter` but for some reason the relpath part is commented out, so it looks like `startdir` (and the corresponding hook) is unused now?

```python
def write_fspath_result(self, fspath, res):
    if fspath != self.currentfspath:
        self.currentfspath = fspath
        #fspath = self.startdir.bestrelpath(fspath)
        self._tw.line()
        #relpath = self.startdir.bestrelpath(fspath)
        self._tw.write(fspath + " ")
    self._tw.write(res)
```

One idea I've had regarding file paths reporting is that if we know all paths prior to reporting (which we do), the `startdir` could be just set like so
```python
startdir = py.path.local(os.path.commonprefix(collected_files))
```
and this would automatically generate nice terminal logs regardless of where the package is physically located, so no conftest hacking is required. Would it make sense to implement it as an option?

Thanks.






More information about the pytest-commit mailing list