Skip to content

A few tiny micro-optimizations/simplifications #7238

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

Merged
merged 4 commits into from
May 23, 2020

Conversation

bluetech
Copy link
Member

No description provided.

bluetech added 4 commits May 22, 2020 14:33
`write_fspath_result` already does this split.
This is already done in pytest_runtest_logstart, so the fspath is
already guaranteed to have been printed (for xdist, it is disabled
anyway).

write_fspath_result is mildly expensive so it is worth avoiding calling
it twice.
@@ -474,10 +473,7 @@ def pytest_runtest_logreport(self, report: TestReport) -> None:
else:
markup = {}
if self.verbosity <= 0:
if not running_xdist and self.showfspath:
self.write_fspath_result(rep.nodeid, letter, **markup)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is never reached?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is reached, but has the same outcome as just the write.

What write_fspath_result does is check whether the path (extracted from the nodeid) is different than the last call to write_fspath_result, and if so, starts a new line and prints the path, before printing the argument.

The reason it's not needed here is that pytest_runtest_logstart already calls write_fspath_result, so the call here (logreport) doesn't.

Because the check it performs is mildly expensive, it's good to avoid it when possible.

@@ -443,8 +443,7 @@ def pytest_runtest_logstart(self, nodeid, location):
self.write_ensure_prefix(line, "")
self.flush()
elif self.showfspath:
fsid = nodeid.split("::")[0]
self.write_fspath_result(fsid, "")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is now different, correct? Or does is it have the same outcome?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

write_fspath_result does this:

fspath = self.config.rootdir.join(nodeid.split("::")[0])

(and doesn't use nodeid otherwise) so the split is redundant here.

Copy link
Member

@nicoddemus nicoddemus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, thanks for the clarifications!

@bluetech bluetech merged commit b38edec into pytest-dev:master May 23, 2020
@bluetech bluetech deleted the micro-optimizations-1 branch June 17, 2020 14:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants