-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
terminal: fix progress report with duplicate nodeids #6599
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
Closed
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
f606077
terminal: fix progress report with duplicate nodeids
blueyed aac97ef
test_same_nodeids
blueyed a5606b4
count setups
blueyed e8e6567
fixup! count setups
blueyed bbd80ef
count in pytest_runtest_logfinish
blueyed c3fcc9a
assert
blueyed be6a7cd
pytest_runtestloop, use name removed in 5939b336c
blueyed cad0319
make use of never used _tests_ran
blueyed f09505d
Merge branch 'master' into fix-progress-same-nodeids
blueyed 9d19f88
Merge branch 'master' into fix-progress-same-nodeids
blueyed dbd3f46
or (rep.when == "setup" and rep.failed)
blueyed f660904
less diff churn
blueyed b6c7c51
s/pytest_runtest_teardown/pytest_runtest_logfinish
blueyed File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Fix percentage progress report with duplicate nodeids. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,10 +12,10 @@ | |
from typing import Any | ||
from typing import Callable | ||
from typing import Dict | ||
from typing import Generator | ||
from typing import List | ||
from typing import Mapping | ||
from typing import Optional | ||
from typing import Set | ||
from typing import Tuple | ||
|
||
import attr | ||
|
@@ -278,7 +278,7 @@ def __init__(self, config: Config, file=None) -> None: | |
self.reportchars = getreportopt(config) | ||
self.hasmarkup = self._tw.hasmarkup | ||
self.isatty = file.isatty() | ||
self._progress_nodeids_reported = set() # type: Set[str] | ||
self._progress_items_reported = 0 | ||
self._show_progress_info = self._determine_show_progress_info() | ||
self._collect_report_last_write = None # type: Optional[float] | ||
|
||
|
@@ -440,6 +440,8 @@ def pytest_runtest_logreport(self, report: TestReport) -> None: | |
else: | ||
markup = None | ||
self._add_stats(category, [rep]) | ||
if rep.when == "call" or (rep.when == "setup" and rep.failed): | ||
self._progress_items_reported += 1 | ||
if not letter and not word: | ||
# probably passed setup/teardown | ||
return | ||
|
@@ -462,7 +464,6 @@ def pytest_runtest_logreport(self, report: TestReport) -> None: | |
else: | ||
self._tw.write(letter, **markup) | ||
else: | ||
self._progress_nodeids_reported.add(rep.nodeid) | ||
line = self._locationline(rep.nodeid, *rep.location) | ||
if not running_xdist: | ||
self.write_ensure_prefix(line, word, **markup) | ||
|
@@ -483,43 +484,51 @@ def pytest_runtest_logreport(self, report: TestReport) -> None: | |
|
||
@property | ||
def _is_last_item(self): | ||
return len(self._progress_nodeids_reported) == self._session.testscollected | ||
return self._progress_items_reported == self._session.testscollected | ||
|
||
def pytest_runtest_logfinish(self, nodeid): | ||
blueyed marked this conversation as resolved.
Show resolved
Hide resolved
|
||
assert self._session | ||
if self.verbosity <= 0 and self._show_progress_info: | ||
if self._show_progress_info == "count": | ||
num_tests = self._session.testscollected | ||
progress_length = len(" [{}/{}]".format(str(num_tests), str(num_tests))) | ||
else: | ||
progress_length = len(" [100%]") | ||
def pytest_runtest_logfinish(self) -> None: | ||
"""Write progress if past edge.""" | ||
if self.verbosity >= 0 or not self._show_progress_info: | ||
return | ||
|
||
self._progress_nodeids_reported.add(nodeid) | ||
if self._show_progress_info == "count": | ||
assert self._session | ||
num_tests = self._session.testscollected | ||
progress_length = len(" [{0}/{0}]".format(num_tests)) | ||
else: | ||
progress_length = len(" [100%]") | ||
|
||
if self._is_last_item: | ||
self._write_progress_information_filling_space() | ||
else: | ||
main_color, _ = self._get_main_color() | ||
w = self._width_of_current_line | ||
past_edge = w + progress_length + 1 >= self._screen_width | ||
if past_edge: | ||
msg = self._get_progress_information_message() | ||
self._tw.write(msg + "\n", **{main_color: True}) | ||
w = self._width_of_current_line | ||
past_edge = w + progress_length + 1 >= self._screen_width | ||
if past_edge: | ||
msg = self._get_progress_information_message() | ||
main_color, _ = self._get_main_color() | ||
self._tw.write(msg + "\n", **{main_color: True}) | ||
|
||
@pytest.hookimpl(hookwrapper=True) | ||
def pytest_runtestloop(self) -> Generator[None, None, None]: | ||
"""Write final progress indicator.""" | ||
yield | ||
if ( | ||
getattr(self, "_tests_ran", False) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should avoid attributes being set but not declared on |
||
and self.verbosity <= 0 | ||
and self._show_progress_info | ||
): | ||
self._write_progress_information_filling_space() | ||
|
||
def _get_progress_information_message(self) -> str: | ||
assert self._session | ||
collected = self._session.testscollected | ||
if self._show_progress_info == "count": | ||
if collected: | ||
progress = self._progress_nodeids_reported | ||
counter_format = "{{:{}d}}".format(len(str(collected))) | ||
format_string = " [{}/{{}}]".format(counter_format) | ||
return format_string.format(len(progress), collected) | ||
return format_string.format(self._progress_items_reported, collected) | ||
return " [ {} / {} ]".format(collected, collected) | ||
else: | ||
if collected: | ||
return " [{:3d}%]".format( | ||
len(self._progress_nodeids_reported) * 100 // collected | ||
self._progress_items_reported * 100 // collected | ||
) | ||
return " [100%]" | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this come after
if not letter and not word:
? Because "probably passed setup/teardown" should not be reported again.