Skip to content

Customize test id on the terminal report #3140

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
fontealpina opened this issue Jan 22, 2018 · 3 comments
Closed

Customize test id on the terminal report #3140

fontealpina opened this issue Jan 22, 2018 · 3 comments
Labels
type: question general question, might be closed after 2 weeks of inactivity

Comments

@fontealpina
Copy link

Running pytest with -v option, I am obtaining an output of this type:
ToolTest/test/bug_001/test.py::TestBug001::test_bug_001 <- test.py PASSED
I would like to customize the test id, e.g. removing <- test.py to get:
ToolTest/test/bug_001/test.py::TestBug001::test_bug_001 PASSED

To do this, I tried to write a plugin with the hook:
def pytest_runtest_logstart(nodeid, location):
but seems that my hook is called after the test id has already been printed on the terminal.
So I was wondering if there is a way to do this?

Thanks

@pytestbot pytestbot added the type: bug problem that needs to be addressed label Jan 22, 2018
@nicoddemus
Copy link
Member

Hi @fontealpina,

This is the code responsible for adding that <-:

pytest/_pytest/terminal.py

Lines 507 to 512 in 0d96a5b

if fspath:
res = mkrel(nodeid).replace("::()", "") # parens-normalization
if nodeid.split("::")[0] != fspath.replace("\\", nodes.SEP):
res += " <- " + self.startdir.bestrelpath(fspath)
else:
res = "[location]"

So it seems the collected node and the actual path are different, which might indicate some other problem or can be fixed in some other way.

Can you provide a reproducible example?

@nicoddemus nicoddemus added type: question general question, might be closed after 2 weeks of inactivity and removed type: bug problem that needs to be addressed labels Jan 22, 2018
@fontealpina
Copy link
Author

Hi,
actually I added a plugin to modify the root dir path:

def pytest_configure(config):     
     config.rootdir = py.path.local(os.getcwd())

My target would be use the cwd as rootdir instead of using the common ancestor directory.
I tried this solution and seems to work apart the <- test.py shown in the terminal.
Maybe can I get this in a different way?
Thanks again

@nicoddemus
Copy link
Member

Maybe can I get this in a different way?

Indeed, that's #1642 and #3127. 😉

I'm closing this for now, feel free to ask any follow up questions though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: question general question, might be closed after 2 weeks of inactivity
Projects
None yet
Development

No branches or pull requests

3 participants