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

Remove paho from mqqt unit test #967

Merged
merged 1 commit into from
Dec 10, 2024
Merged

Remove paho from mqqt unit test #967

merged 1 commit into from
Dec 10, 2024

Conversation

twiggler
Copy link
Contributor

@twiggler twiggler commented Dec 6, 2024

We remove an import at the top, but now have to import the unit under test in the test itself.

Closes #926

@twiggler twiggler marked this pull request as ready for review December 6, 2024 09:30
@twiggler twiggler requested a review from Miauwkeru December 6, 2024 09:30
Copy link

codecov bot commented Dec 6, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 77.71%. Comparing base (aab863c) to head (d79a675).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #967   +/-   ##
=======================================
  Coverage   77.71%   77.71%           
=======================================
  Files         326      326           
  Lines       28543    28543           
=======================================
  Hits        22183    22183           
  Misses       6360     6360           
Flag Coverage Δ
unittests 77.71% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@Miauwkeru Miauwkeru left a comment

Choose a reason for hiding this comment

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

It might also be an idea to remove mqtt from line 83 of the pyproject.toml as there now shouldn't be a dependency requiring it anymore during tests no?

Comment on lines 102 to 104
monkeypatch.setitem(sys.modules, "paho", mock_mqtt)
monkeypatch.setitem(sys.modules, "paho.mqtt", mock_mqtt.mqtt)
monkeypatch.setitem(sys.modules, "paho.mqtt.client", mock_mqtt.mqtt.client)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this part is more useful in a fixture, and that all the other tests use that fixture.
as it now changes the global state of modules and doesn't clean it up afterwards.

It will throw import errors as soon as paho.mqtt is removed.

Copy link
Contributor Author

@twiggler twiggler Dec 9, 2024

Choose a reason for hiding this comment

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

In https://docs.pytest.org/en/stable/how-to/monkeypatch.html#how-to-monkeypatch-mock-modules-and-environments it says:

"The modifications will be undone after the requesting test function or fixture has finished" (emphasis mine)

(There is another problem though: the broker defines the client as an instance variable)

Update: "It will throw import errors as soon as paho.mqtt is removed" is indeed a problem.
Added fixture

@twiggler
Copy link
Contributor Author

twiggler commented Dec 9, 2024

It might also be an idea to remove mqtt from line 83 of the pyproject.toml as there now shouldn't be a dependency requiring it anymore during tests no?

@Miauwkeru It is no longer required for the test, but it should still be when using the mqtt loader right?

Update: Understand now, dev are the test dependencies

We remove an import at the top, but now have to import the unit under test in the test itself.
@twiggler twiggler merged commit 300f110 into main Dec 10, 2024
18 of 20 checks passed
@twiggler twiggler deleted the remove_paho branch December 10, 2024 10:13
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 dependency on paho-mqtt in unit test
2 participants