Skip to content

Conversation

rpoisel
Copy link
Contributor

@rpoisel rpoisel commented Aug 18, 2024

Description

This PR introduces Python typing hints to the pytest specific components of the labgrid framework. These additions can be seen as initial steps towards enhancing the overall code navigation experience and improving the effectiveness of static code analysis tools.

Checklist

  • Documentation for the feature
  • Tests for the feature
  • PR has been tested

@rpoisel rpoisel force-pushed the dev-add-pytest-plugin-typing-hints branch 3 times, most recently from b9f455c to 200d915 Compare August 18, 2024 14:11
"""
import os
import warnings
from typing import Dict
Copy link
Contributor

Choose a reason for hiding this comment

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

Does Labgrid sort its imports?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's the way ruff sorts imports with the current configuration in this repo.

Would you prefer them to be in a different order?

Copy link
Contributor

Choose a reason for hiding this comment

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

No, I suppose I just don't understand how the ordering works

Perhaps 'warnings' is consider an internal module and 'typing' is not?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, I see. Ruff puts from imports after imports without the from keyword.

"pytest_configure",
"pytest_collection_modifyitems",
"pytest_cmdline_main",
]
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be in a separate commit?

target = env.get_target(target_name)
except UserError as e:
pytest.exit(e)
pytest.exit(str(e))
Copy link
Contributor

Choose a reason for hiding this comment

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

This change seems to be unrelated to typing? Or does it fix a bug? If so, best to put the bug-fixes first, in one or more separate commits.

Copy link
Contributor Author

@rpoisel rpoisel Aug 29, 2024

Choose a reason for hiding this comment

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

Actually, this fixes that the wrong type of the reason parameter is passed to the pytest.exit() function: pytest.exit.


def test_config(short_test):
with pexpect.spawn(f'pytest --traceconfig {short_test}') as spawn:
with pexpect.spawn(f"pytest --traceconfig {short_test}") as spawn:
Copy link
Contributor

Choose a reason for hiding this comment

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

Is Labgrid supposed to use " instead of ' ? I see both, I have been wondering

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, I'll make sure these things remain untouched in this PR.

Personally, I'd prefer them to be consistent (whether it's ' or ").

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree. I much prefer ' since it is easier to distinguish as small font sizes, but Labgrid seems to use both

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just updated the pyproject.toml file to contain:

[tool.ruff.format]
quote-style = "single"

Actually, I'd suggest to re-format the whole code base. But this should go into a dedicated PR in my view.

In this PR, however, I already re-formatted the tests/test_fixtures.py file to this new formatting rule anyways.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, this does not work yet. All sources would have to be re-formatted this way before passing CI checks.

As a quick workaround I applied this setting to the tests/test_fixtures.py file, but removed it from the pyproject.toml file.

CHANGES.rst Outdated
New Features in 24.1
~~~~~~~~~~~~~~~~~~~~
- All components can be installed into the same virtualenv again.
- The ``pytest`` specific parts of the labgrid framework now have typing hints.
Copy link
Contributor

Choose a reason for hiding this comment

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

pytest-specific

@rpoisel rpoisel force-pushed the dev-add-pytest-plugin-typing-hints branch 2 times, most recently from 79fb518 to 7df770f Compare December 23, 2024 09:12
Copy link

codecov bot commented Dec 23, 2024

Codecov Report

❌ Patch coverage is 82.69231% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 46.8%. Comparing base (fd3f528) to head (83dfee8).

Files with missing lines Patch % Lines
labgrid/pytestplugin/hooks.py 80.0% 5 Missing ⚠️
labgrid/logging.py 71.4% 2 Missing ⚠️
labgrid/pytestplugin/fixtures.py 91.6% 1 Missing ⚠️
labgrid/remote/client.py 50.0% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##           master   #1478     +/-   ##
========================================
+ Coverage    45.4%   46.8%   +1.4%     
========================================
  Files         172     172             
  Lines       13501   13519     +18     
========================================
+ Hits         6131    6340    +209     
+ Misses       7370    7179    -191     
Flag Coverage Δ
3.10 46.9% <82.6%> (+1.4%) ⬆️
3.11 46.9% <82.6%> (+1.4%) ⬆️
3.12 46.9% <82.6%> (+1.4%) ⬆️
3.13 46.8% <82.6%> (+1.4%) ⬆️
3.14 46.8% <82.6%> (+1.4%) ⬆️
3.9 46.9% <82.6%> (+1.4%) ⬆️

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.

@rpoisel
Copy link
Contributor Author

rpoisel commented Dec 23, 2024

@sjg20, could you please review my PR again? All your comments should be implemented/resolved now.

To be honest, I'd love to see this PR merged into labgrid as it improves the code navigation and static code analysis experience quite a lot.

@rpoisel rpoisel requested a review from sjg20 December 23, 2024 09:27
@rpoisel rpoisel force-pushed the dev-add-pytest-plugin-typing-hints branch from 7df770f to a8f887c Compare January 6, 2025 17:28
@rpoisel rpoisel force-pushed the dev-add-pytest-plugin-typing-hints branch 7 times, most recently from 854f9ac to 629c116 Compare October 5, 2025 11:48
@rpoisel
Copy link
Contributor Author

rpoisel commented Oct 5, 2025

@sjg20, could you please have a look? I just made sure this PR can be merged without conflicts.

Add this logging level without changing Python’s internal logging module.
This maintains architectural integrity and clarifies that the level is labgrid-specific.

Signed-off-by: Rainer Poisel <[email protected]>
@rpoisel rpoisel force-pushed the dev-add-pytest-plugin-typing-hints branch from 629c116 to e64359a Compare October 10, 2025 13:15
@Bastian-Krause
Copy link
Member

The Python 3.14 errors should be fixed when rebasing on latest master.

@rpoisel
Copy link
Contributor Author

rpoisel commented Oct 10, 2025

The Python 3.14 errors should be fixed when rebasing on latest master.

Thanks for the hint! Just found out that Python 3.14 support has been added recently.

I'd be very happy to get this PR merged asap. It is already over 1 year old and rebasing it always takes some effort.

Hopefully, I get the errors fixed today evening (CEST) or tomorrow.

@rpoisel rpoisel force-pushed the dev-add-pytest-plugin-typing-hints branch from e64359a to 83dfee8 Compare October 10, 2025 20:07
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