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[tests]: clear log capture at start of local mode solver test #2171

Merged
merged 1 commit into from
Jan 16, 2025

Conversation

yaugenst-flex
Copy link
Collaborator

@yaugenst-flex yaugenst-flex commented Jan 15, 2025

This is a band-aid fix for the test coupling. Works for this specific case, but we'll need to do more robust warning capturing if we want to avoid dealing with this in the future.

Copy link

💑 Decouple tests

@caseyflex caseyflex self-requested a review January 15, 2025 16:28
Copy link
Contributor

@caseyflex caseyflex left a comment

Choose a reason for hiding this comment

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

Actually, maybe we should wrap this in

with AssertLogLevel(log_capture, ...)

rather than the current context-free approach.

this might be the appropriate solution throughout?

I think the old assert_log_level syntax should be removed globally in favor of with AssertLogLevel(log_capture, "WARNING", contains_str="..."):

would this fix the threaded test issue?

@yaugenst-flex
Copy link
Collaborator Author

yaugenst-flex commented Jan 15, 2025

That's probably a good idea in general but does not fix the underlying issue here, since the context manager does not clear the captured logs. So essentially,

with AssertLogLevel(log_capture, "WARNING", contains_str="ModeSpec") as ctx:
    assert modes.n_group is None
    assert len(ctx.records) == 1

and

assert modes.n_group is None
assert len(log_capture) == 1

are equivalent in that sense. I changed it so we are not checking the length of the records at all and are instead only checking the actual message generated within the context manager, which should be ok for these tests?

I'll make an issue for doing this change globally but for now this will fix the failing CI.

@yaugenst-flex yaugenst-flex force-pushed the yaugenst-flex/fix-test-coupling branch from e974db3 to 3573f46 Compare January 15, 2025 19:34
@yaugenst-flex
Copy link
Collaborator Author

#2172

@caseyflex
Copy link
Contributor

Hmmm, I would think it would fix the underlying issue since the context manager AssertLogLevel only checks records logged within its context. Is that incorrect?

@yaugenst-flex
Copy link
Collaborator Author

The way that AssertLogLevel is currently implemented it does not keep track of how many warnings were generated within its context, this is only calculated on __exit__ to determine which records to run assert_log_level against.

I think more fundamentally the issue is that many of our tests are written in a way that doesn't isolate individual warning cases, and some even work around the fact that there is some global logging state. I was intending this PR to be a quick fix to get CI passing so that it's not blocking other PRs anymore, but I guess I can come up with a more complete fix too.

Copy link
Contributor

@caseyflex caseyflex left a comment

Choose a reason for hiding this comment

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

Got it now regarding the context manager. Yeah up to you, this sounds good as a quick fix!

@yaugenst-flex yaugenst-flex force-pushed the yaugenst-flex/fix-test-coupling branch 2 times, most recently from 4bdfd95 to b5f7e77 Compare January 16, 2025 09:32
@yaugenst-flex
Copy link
Collaborator Author

Ok, bit the bullet. Main changes are:

  • log_capture now cleans up after itself.
  • AssertLogLevel now uses its own log handler (AssertLogLevelHandler) that it registers upon entry and deletes upon exit of the context. Within the context, only logs recorded by this handler will be checked. It also exposes a num_records property to make it easy to check the number of warnings raised within the context. Due to this, AssertLogLevel now no longer depends on an external log handler, so log_capture is not needed anymore. Good riddance, because AssertLogLevel used to rely on the fact that the records were passed by reference and manipulated by an outside source.
  • Updated all tests to use AssertLogLevel where appropriate.

For the most part, the log_capture fixture is now not necessary anymore. The only use case for it is in conjunction with assert_log_level to check whether certain warnings (usually meaning no warnings) were raised up until a certain point in the test.

@caseyflex
Copy link
Contributor

caseyflex commented Jan 16, 2025

@yaugenst-flex this is awesome! should be much cleaner and safer this way.

One comment is that it really does seem like we can just get rid of log_capture altogether now. assert_log_level is only used in a couple places, where it isn't really needed -- I put it there just to ensure that the warning was coming from the correct call, before we had AssertLogLevel. If we wanted to check warnings up to a certain point, we could just wrap the whole block in AssertLogLevel. And keeping log_capture around seems more likely to cause these issues to crop up again in the future.

@yaugenst-flex yaugenst-flex force-pushed the yaugenst-flex/fix-test-coupling branch from b5f7e77 to 7e2acac Compare January 16, 2025 10:21
@yaugenst-flex
Copy link
Collaborator Author

Yeah good point, I was considering this but was a bit hesitant to change the behavior of the tests. Updated, log_capture is gone :)

Copy link
Collaborator

@daquinteroflex daquinteroflex left a comment

Choose a reason for hiding this comment

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

Nice idea on the raise with AssertLogLevel! Looks good, thanks Yannick.

@yaugenst-flex yaugenst-flex force-pushed the yaugenst-flex/fix-test-coupling branch from 7e2acac to 7672e35 Compare January 16, 2025 15:35
@yaugenst-flex yaugenst-flex merged commit 7c9f521 into pre/2.8 Jan 16, 2025
15 checks passed
@yaugenst-flex yaugenst-flex deleted the yaugenst-flex/fix-test-coupling branch January 16, 2025 16:44
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove legacy assert_log_level in favor of AssertLogLevel in tests
4 participants