eclipse / paho.mqtt.python

paho.mqtt.python
Other
2.13k stars 723 forks source link

Convert homespun tests to conventional tests #780

Closed akx closed 6 months ago

akx commented 6 months ago

This PR converts the homespun test/ code to (what I think is) pretty idiomatic Python/Pytest code.

I think I got everything right, the original code was pretty hairy. 😂

Would probably be even better if the client code was included in the tests themselves to avoid having to hop between files.

Fixes #768

cclauss commented 6 months ago

pytest, not py.test since version 3.0

pytest-dev/pytest#1629

akx commented 6 months ago

pytest, not py.test since version 3.0

old naming dies hard 😂

akx commented 6 months ago

Ah, I'll improve this a little more – we'll want to be sure the client process didn't die with an exception and so on...

Also turns out the original author(s) of the clients have been funny with

rc = -1
... = Client(..., rc)

where they actually mean

... = Client(..., clean_session=True)
akx commented 6 months ago

Phew, this PR underwent a bit of a metamorphosis since last night, but I think it's much, much better now. We will now be able to automagically catch exceptions from the clients, and there's (almost) no playing with return codes and so on.

I also fixed the way port 1888 was being hard-coded; if you install pytest-xdist, you can now run all tests in parallel with e.g. pytest -n8

A bunch of actually unused/no-op code also got removed – a 723 line removal is pretty good in my books 😁

I think there's still more unused code, but the MQTTv5 tests would need to be fixed first (#769) to see if that's the case; they don't actually run against the current master of https://github.com/eclipse/paho.mqtt.testing...

akx commented 6 months ago

Great works ! That huge works, thank for your time.

No problem, it was a nice brain workout while watching Christmas movies and drinking mulled wine and cognac... 😂