Skip to content

Replace self.mock_* pairs by self.mocked_* context managers#5157

Open
Flamefire wants to merge 1 commit into
easybuilders:developfrom
Flamefire:mocked-stdstream
Open

Replace self.mock_* pairs by self.mocked_* context managers#5157
Flamefire wants to merge 1 commit into
easybuilders:developfrom
Flamefire:mocked-stdstream

Conversation

@Flamefire

Copy link
Copy Markdown
Contributor

Make sure cleanup happens

Followup to #5125 by adding the force_tty parameter to the context managers

  • Diff can be viewed easiest by ignoring space changes (most of the diff is indents)
  • Partially written by Github Copilot, partially RegEx and manual where necessary
  • Kept in one place where the whole test is run with mocked outputs

Should be merged soon as this is prone to merge conflicts

@Flamefire Flamefire force-pushed the mocked-stdstream branch 2 times, most recently from 6bb272a to 359f379 Compare April 2, 2026 13:27
@boegel boegel added the tests label Apr 7, 2026
@boegel boegel added this to the release after 5.3.0 milestone Apr 7, 2026
Comment thread easybuild/base/testing.py

@contextmanager
def mocked_stdout(self):
def mocked_stdout(self, force_tty=False):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

force_tty should be used when turning the mocked pipe ON and not when turning it OFF (enabling it on the normal stdout/stderr should be a separate operation if ever needed)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is the function that turns the mocked pipe ON. Or do you mean something different?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I mean it should be

self.mock_stdout(True, force_tty=force_tty)
...
self.mock_stdout(False)

instead of the other way around

wanted to suggest it as a change but i think the tool does not like suggestions going over deleted lines(?) and was giving weird stuff

Comment thread easybuild/base/testing.py

@contextmanager
def mocked_stderr(self):
def mocked_stderr(self, force_tty=False):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Same as above

self.mock_stderr(False)
with self.mocked_stdout_stderr():
self.assertErrorRegex(EasyBuildError, error_pattern, eb.fetch_step)
stderr = self.get_stderr().strip()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I assume here it was originally an error where the stdout mocking was not being turned off?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Exactly. That's one of the reasons I want to get rid of the manual turn-on/off as soon as possible.

Comment thread test/framework/github.py
self.assertTrue(re.match('^[0-9a-f]{40}$', read_file(shafile)))
self.assertExists(os.path.join(repodir, 'easybuild', 'easyblocks', '__init__.py'))
self.mock_stdout(False)
# stdout capture released by context manager above

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do we need this comment?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants