Skip to content

Pytest tests and CI - #58

Merged
jonrebm merged 7 commits into
pengutronix:mainfrom
jonrebm:pytest
Jul 13, 2026
Merged

Pytest tests and CI#58
jonrebm merged 7 commits into
pengutronix:mainfrom
jonrebm:pytest

Conversation

@jonrebm

@jonrebm jonrebm commented Dec 14, 2025

Copy link
Copy Markdown
Contributor

I've done some cleanup in the microcom codebase, and created a CI workflow to catch many of the encountered issues in the future.

These tests fail now, as long as the PRs resolving the issues are still open:

@jonrebm
jonrebm force-pushed the pytest branch 2 times, most recently from fbd0f44 to 86dea61 Compare December 14, 2025 19:57
Comment thread microcom.c
Comment thread microcom.c Outdated
Comment thread test/test_telnet.py
Comment on lines +28 to +30
conn.sendall(buf)
time.sleep(0.01) # sadly without this, microcom may miss the transmission
sock.close()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could this hardcoded sleep result in flaky tests in the future?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, definitely. I'm not sure why this is even needed. I'd expect that expect blocks until microcom has connected via TCP and that from this point whatever the server sends should definitely reach microcom. I suspect this is actually a workaround for a microcom bug.
As long as it's needed, should 0.01 turn out flaky on a slow runner, 0.1 should still run the tests quick enough.

But yes bad bad hack!

Comment thread test/test_telnet.py Outdated
@hnez

hnez commented Dec 16, 2025

Copy link
Copy Markdown
Member

I like it! Since this adds python code to the repository: should the CI also run e.g. ruff format and ruff check now?

@jonrebm
jonrebm marked this pull request as draft December 16, 2025 13:56
Comment thread test/test_telnet.py
Comment on lines +17 to +19
@pytest.fixture
def telnet_recv(cmd):
def _recv(buf, timeout=1):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Define helper functions directly; there is no need to use fixtures for that.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The reason that this is a fixture and not a helper function is that it directly depends on the cmd fixture. My understanding is that only tests and fixtures can depend on other fixtures, therefore a fixture is adequate here.

As there's little reason why a test that uses telnet_recv would also use cmd, there is no reason to pass the cmd fixture to the test only to then pass it on to telnet_recv.
So I'd prefer this:

def test_a(telnet_recv):
    assert telnet_recv("abc") == "abc"

Over this:

def test_a(cmd):
    assert telnet_recv(cmd, "abc") == "abc"

The difference is negligible in this case but adding more dependent fixtures to telnet_recv in the latter solution would be suboptimal, because they'd all need to be added to each of the tests even if the test code itself isn't touched

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Using a fixture for helper functions such as these hides that telnet_recv actually uses the cmd fixture, making the code unnecessarily hard to read.

@jonrebm

jonrebm commented Dec 16, 2025

Copy link
Copy Markdown
Contributor Author

Thanks!
Well at least I could run ruff format next time I update this branch... But yes I'll add it to CI too if that's preinstalled on the runner atleast

The quiet switch silences all printing to stdout during normal
operation, but leaves the interactive console and all error messages
functional.

Useful for automation such as in CI.

Signed-off-by: Jonas Rebmann <jre@pengutronix.de>
jonrebm added 6 commits July 13, 2026 15:36
I set up those tests for the issues with the current telnet
implementation. They can serve as regression tests after the issues have
been resolved.

Add them as the first integration tests.
Add pythons bytecode cache files to gitignore.

Signed-off-by: Jonas Rebmann <jre@pengutronix.de>
 - fix dependency installation
 - invoke pytest
 - don't build an unneeded release tarball

Signed-off-by: Jonas Rebmann <jre@pengutronix.de>
This has proven to be useful to catch out-of-bounds access and I hope
can prevent some cases of success by chance when testing microcom.

Signed-off-by: Jonas Rebmann <jre@pengutronix.de>
Enforce the C style from uncrustify.cfg. Format one line that didn't
follow the style yet.

Signed-off-by: Jonas Rebmann <jre@pengutronix.de>
Signed-off-by: Jonas Rebmann <jre@pengutronix.de>
Amongst others, this catches uninitialized memory access, which libasan
does not.

Signed-off-by: Jonas Rebmann <jre@pengutronix.de>
@jonrebm
jonrebm marked this pull request as ready for review July 13, 2026 13:41
@jonrebm
jonrebm merged commit eb3c224 into pengutronix:main Jul 13, 2026
3 checks passed
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.

3 participants