Skip to content
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

fix(unit_test): prevent logging from raising exceptions after tests #6001

Merged
merged 1 commit into from
Apr 10, 2023

Conversation

tchaikov
Copy link
Contributor

pytest's capsys just closes the stdout when done with tests. there are issues tracking this problem, see pytest-dev/pytest#5577 . but we adds a handler which redirect the logging messages to stdout. so, once pytest finishes testing, exceptions are raised when writing logging messages, like

22:37:20    File "/usr/local/lib/python3.10/logging/__init__.py", line 1101, in emit
22:37:20      stream.write(msg + self.terminator)
22:37:20  ValueError: I/O operation on closed file.

so, in this change, logging.raiseExceptions is disabled when pytest's session finishes.

Fixes #6000

PR pre-checks (self review)

  • I followed KISS principle and best practices
  • I didn't leave commented-out/debugging code
  • I added the relevant backport labels
  • New configuration option are added and documented (in sdcm/sct_config.py)
  • I have added tests to cover my changes (Infrastructure only - under unit-test/ folder)
  • All new and existing unit tests passed (CI)
  • I have updated the Readme/doc folder accordingly (if needed)

pytest's capsys just closes the stdout when done with tests. there are
issues tracking this problem, see pytest-dev/pytest#5577 .
but we adds a handler which redirect the logging messages to stdout. so,
once pytest finishes testing, exceptions are raised when writing logging
messages, like
```
22:37:20    File "/usr/local/lib/python3.10/logging/__init__.py", line 1101, in emit
22:37:20      stream.write(msg + self.terminator)
22:37:20  ValueError: I/O operation on closed file.
```
so, in this change, `logging.raiseExceptions` is disabled when pytest's
session finishes.

Fixes scylladb#6000

Signed-off-by: Kefu Chai <kefu.chai@scylladb.com>
@fruch fruch added the backport/none Backport is not required label Apr 10, 2023
Copy link
Contributor

@fruch fruch left a comment

Choose a reason for hiding this comment

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

LGTM,

still we have a few PytestUnhandledThreadExceptionWarning being raised during the tests
but that's by very specific test that doesn't check their background threads for some reason.

Copy link
Contributor

@vponomaryov vponomaryov left a comment

Choose a reason for hiding this comment

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

LGTM

@fruch fruch merged commit 0435861 into scylladb:master Apr 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport/none Backport is not required
Projects
None yet
Development

Successfully merging this pull request may close these issues.

logger is not able to write to log file after tests complete
3 participants