Skip to content

Conversation

Copy link

Copilot AI commented Jul 24, 2025

Summary

Fixes pytest warnings that occur when using pytest.raises(..., match="") with an empty string pattern. The warnings were introduced in newer versions of pytest and appear in several test cases.

Problem

The test suite was generating warnings like:

pytest.PytestWarning: matching against an empty string will *always* pass. If you want to check for an empty message you need to pass '^$'. If you don't want to match you should pass `None` or leave out the parameter.

This occurred in the _assert_is_disconnected helper function which was using match=r"" when testing ClientNotConnected exceptions.

Solution

  • Removed the match=r"" parameter from pytest.raises(ClientNotConnected) calls since the tests only need to verify the exception type and attributes, not the message content
  • Removed duplicate test block that was testing the exact same functionality twice
  • Preserved all existing test behavior - the tests still validate exception attributes (server_url and operation) as before

Testing

All previously failing tests now pass without warnings:

  • test_base_api_client_init[auto_connect=False]
  • test_base_api_client_disconnect
  • test_base_api_client_async_context_manager[auto_connect=True]
  • test_base_api_client_async_context_manager[auto_connect=False]

The fix is minimal and surgical - it only removes the problematic empty match pattern while maintaining all existing test functionality.

Copilot AI changed the title [WIP] Please create a pull request to fix the new warning about pytest.raises(..., match="^$") as reported by this pytest output: ``` =================================== FAILURES =================================== ________________ test_base_api_client_i... Fix pytest warning about empty match parameter in pytest.raises Jul 24, 2025
Copilot AI requested a review from llucax July 24, 2025 12:25
Copilot finished work on behalf of llucax July 24, 2025 12:25
@llucax llucax added this to the v0.12.0 milestone Jul 24, 2025
Comment on lines -31 to -35
with pytest.raises(ClientNotConnected, match=r"") as exc_info:
_ = client.channel
exc = exc_info.value
assert exc.server_url == _DEFAULT_SERVER_URL
assert exc.operation == "channel"
Copy link
Contributor

Choose a reason for hiding this comment

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

Just for the records this duplicated block looks like a wrong revert. At some point we had 2 blocks but one tested client.stub instead:

But then we removed the client.stub property as it needs to return a async version of the stub, which can only be done by the sub-class, but it looks like instead of being removed it duplicated the test for client.channel.

@llucax llucax marked this pull request as ready for review July 24, 2025 12:32
@github-actions github-actions bot added the part:tests Affects the unit, integration and performance (benchmarks) tests label Jul 24, 2025
@llucax llucax requested a review from a team as a code owner July 24, 2025 12:32
@llucax llucax requested review from florian-wagner-frequenz and removed request for a team July 24, 2025 12:32
@llucax llucax added the cmd:skip-release-notes It is not necessary to update release notes for this PR label Jul 24, 2025
@llucax llucax merged commit 6937997 into dependabot/pip/minor-01cf8d849b Jul 24, 2025
24 of 25 checks passed
@llucax llucax deleted the copilot/fix-bbe4398b-da3d-4523-a3ea-671df12a4fa8 branch July 24, 2025 12:35
@llucax llucax modified the milestones: v0.12.0, v0.11.1 Sep 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cmd:skip-release-notes It is not necessary to update release notes for this PR part:tests Affects the unit, integration and performance (benchmarks) tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants