-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Improve stepwise to not forget failed tests #13122
Improve stepwise to not forget failed tests #13122
Conversation
b261556
to
d7dfd4a
Compare
96c3adb
to
95d2390
Compare
I'm worried about this too. Imagine someone:
If you've long forgotten about your previous session, that'll be quite surprising... I don't really have a solution unfortunately. A couple of ideas:
I don't really like the first three as they all come with their own downsides, but maybe the fourth one would at least partially help? |
@The-Compiler thanks for the consideration, indeed now that I think about it more it might be surprising unless the user is aware of the change.
I think those two are actually reasonable, and they even make sense to be implemented together. I will take a stab at them. Thanks! |
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.
Amazing work, thanks! Left a couple comments, mainly small nitpicks.
Now `--stepwise` will remember the last failed test, even if the previous pytest invocations did not pass `--stepwise`. Previously it would always clear the cache if not active, which hinders certain interactive workflows, which is the prime use cases for the flag.
cdf06c3
to
1f7a151
Compare
@The-Compiler ready for another review. 👍 |
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.
Sorry for the delay! Wanted to play around with this a bit rather than just looking at the diff, and didn't get around to it yet.
One last thing I noticed regarding the output, and then I think this is good to go!
src/_pytest/stepwise.py
Outdated
else: | ||
self.report_status = f"skipping {failed_index} already passed items." | ||
self.report_status.append( | ||
f"skipping {failed_index} already passed items (cache from {self.cached_info.last_cache_date}," |
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.
f"skipping {failed_index} already passed items (cache from {self.cached_info.last_cache_date}," | |
f"skipping {failed_index} already passed items (cache from {self.cached_info.last_cache_date:%c}," |
maybe, where %c
is "Locale’s appropriate date and time representation."?
Without this, it gets displayed as e.g. cache from 2025-01-15 14:25:45.458813
which seems a bit verbose, and the fractional seconds don't really add any useful information.
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.
I did try that initially, but to me it showed up as the default locale (C
): IIUC we need to call locale.setlocale
at some point explicitly for %c
to work properly, otherwise it will always use the C
locale (and we cannot do that because this is a global setting, which pytest definitely should not touch IMO).
But I might be wrong, can you test that in your machine?
If %c
does not work, we might explicitly use %YY-%M-%d %h:%m:%s
to get rid of the fractional seconds, which I agree is not useful.
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.
Oh wow, looks like it! My locale setup is a bit weird at the moment anyways (experimented with en_DK to get proper dates, but turns out it's not supported everywhere so now I get a mess of formats...). Because of that, I expected that to be an issue on my end.
What do you think about making a timedelta
to now and then just formatting that in instead? That would then show up as 0:00:10 ago
or 42 days, 1:23:45 ago
which seems a much nicer format for the information we actually want to convey here.
edit: Whoops, I completely neglected that this would show microseconds too... I suppose that could be fixed with a datetime.timedelta(seconds=int(td.total_seconds()))
(with td
being the original delta).
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.
Good idea about timedelta
, will do.
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.
Done.
I considered only showing that information if the cache was "old", but then what could be considered an "old" cache? 1 hr? 1 day? In the ended I kept it simple and always show the cache age for now.
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.
Hehe, I have been thinking about that as well, and came to the same conclusion as you did 😅
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.
Thanks for sticking with this, looks great! Will merge in a day or two if nobody else wants to take a look.
Thanks again! ✨ |
Thanks @The-Compiler for merging! However that would be better as a squash probably. 👍 |
I did consider that and decide against it, given that there were significant changes/amendments in the history of this PR. |
Now
--stepwise
will remember the last failed test, even if the previous pytest invocations did not receive--stepwise
.Previously it would always clear the cache if not active, which hinders certain interactive workflows, which is the prime use case for the flag.