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

Convert homespun tests to conventional tests #780

Merged
merged 3 commits into from
Dec 24, 2023

Conversation

akx
Copy link
Contributor

@akx akx commented Dec 23, 2023

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

@akx akx force-pushed the convert-strange-tests branch 3 times, most recently from e889845 to e7b0a34 Compare December 23, 2023 20:48
@akx akx marked this pull request as ready for review December 23, 2023 20:52
tests/lib/clients/01-asyncio.py Outdated Show resolved Hide resolved
tests/lib/test_01_asyncio.py Show resolved Hide resolved
tests/lib/test_01_asyncio.py Outdated Show resolved Hide resolved
@cclauss
Copy link
Contributor

cclauss commented Dec 23, 2023

pytest, not py.test since version 3.0

pytest-dev/pytest#1629

@akx akx changed the title Convert homespun tests to Py.test Convert homespun tests to conventional tests Dec 24, 2023
@akx akx force-pushed the convert-strange-tests branch 3 times, most recently from 5885aba to bf83885 Compare December 24, 2023 08:58
@akx
Copy link
Contributor Author

akx commented Dec 24, 2023

pytest, not py.test since version 3.0

old naming dies hard 😂

@akx akx marked this pull request as draft December 24, 2023 09:08
@akx
Copy link
Contributor Author

akx commented Dec 24, 2023

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 akx force-pushed the convert-strange-tests branch 5 times, most recently from 63f1758 to e381f43 Compare December 24, 2023 12:12
@akx
Copy link
Contributor Author

akx commented Dec 24, 2023

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 akx marked this pull request as ready for review December 24, 2023 12:48
@akx akx requested a review from PierreF December 24, 2023 13:43
Copy link
Contributor

@PierreF PierreF left a comment

Choose a reason for hiding this comment

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

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

@@ -25,13 +24,26 @@ class TestError(Exception):
def __init__(self, message="Mismatched packets"):
self.message = message


def bind_to_any_free_port(sock) -> int:
Copy link
Contributor

Choose a reason for hiding this comment

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

❤️ I will no longer have strange error when I run a real broker on port 1888 and run paho test.

PYTHONPATH=f"{tests_path}{os.pathsep}{os.environ.get('PYTHONPATH', '')}",
)
assert 'PAHO_SERVER_PORT' in env, "PAHO_SERVER_PORT must be set in the environment when starting a client"
# TODO: it would be nice to run this under `coverage` too!
Copy link
Contributor

Choose a reason for hiding this comment

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

We might be able to have coverage done it instead of a subprocess we start a thread. But this is probably easy to said and harder to implement. Anyway I think it not in the scope of this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

pytest-cov actually hooks things up so subprocesses work OOTB, which was nice to notice!

@PierreF PierreF merged commit 805cb7e into eclipse:master Dec 24, 2023
10 checks passed
@akx
Copy link
Contributor Author

akx commented Dec 24, 2023

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... 😂

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.

Convert test/Makefile tests to regular py.test tests
3 participants