Fix flaky ./pants idea-plugin
when using Python 3 by properly using ConsoleTask interface
#7460
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.
Problem
The Idea plugin integration tests would frequently flake with Python 3.
This appears to be because the task is a
ConsoleTask
, but it overridesexecute()
when it is instead expected to overrideconsole_output()
. With this override, we would no longer callself._outstream.flush()
, so the tests would sometimes complain that there was no entry in the--output-file
, as the change would not always be persisted. It makes sense that this did not start flaking until Python 3, because IO streams changed their behavior in Python 3.Refer to
ConsoleTask
for everything we need to do to properly output to the console and files:pants/src/python/pants/task/console_task.py
Lines 52 to 62 in e620a9e
Will close #7150.
Solution
No longer override
execute()
and instead move the logic intoconsole_output()
.Result
The tests no longer flake.
This was confirmed locally by creating the script
untilfail
:Then running
./untilfail ./pants clean-all test.pytest tests/python/pants_test/backend/project_info/tasks:idea_plugin_integration -- -k test_idea_plugin_single_target
for 10 minutes on both macOS and Ubuntu without fail.