Skip to content

test local worktree with pytest by default#884

Merged
pdgendt merged 1 commit intozephyrproject-rtos:mainfrom
thorsten-klein:pytest-ini-options
Nov 28, 2025
Merged

test local worktree with pytest by default#884
pdgendt merged 1 commit intozephyrproject-rtos:mainfrom
thorsten-klein:pytest-ini-options

Conversation

@thorsten-klein
Copy link
Copy Markdown
Contributor

@thorsten-klein thorsten-klein commented Nov 19, 2025

Successor of #883 where this was discussed.

Enable pytest pythonpath=src by default to run tests against the local worktree. poe test now also tests the local worktree.
In CI, the newly added poe gh-test is run in order to test the locally installed package (installed via uv).
gh-test explicitly unsets pytest option pythonpath and creates a coverage report.

During manual tests it was observed that uv always appends the src directory to sys.path. Luckily, this is not a problem as the path is appended and the path of the installed west comes first.

@codecov
Copy link
Copy Markdown

codecov bot commented Nov 19, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 84.93%. Comparing base (de789c8) to head (8c5f58a).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #884   +/-   ##
=======================================
  Coverage   84.93%   84.93%           
=======================================
  Files          11       11           
  Lines        3444     3444           
=======================================
  Hits         2925     2925           
  Misses        519      519           

@thorsten-klein thorsten-klein force-pushed the pytest-ini-options branch 4 times, most recently from 42c3f00 to 1fb8293 Compare November 19, 2025 10:51
@pdgendt pdgendt requested a review from marc-hb November 19, 2025 10:56
Copy link
Copy Markdown
Collaborator

@marc-hb marc-hb left a comment

Choose a reason for hiding this comment

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

No major concern, see below.

README.rst Outdated
# Manually (test the local copy)
pytest -o pythonpath=src
# Manually (test the installed west version)
pytest -o pythonpath=
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Is this really needed? Packaging issues should already be found by uv.

Unless there's value in testing and older version with newer tests or vice-versa? Very "advanced" then. Maybe move this trick outside the README.rst, how about a comment just above the pythonpath = "src" line? So people don't assume they have to change that line.

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, this is very advanced. It is a good idea to move it to pyproject.toml


[tool.poe.tasks.test]
cmd = "python -m pytest -v -W error --junitxml=junit.xml -o junit_family=xunit1 --cov-report=html --cov-config=pyproject.toml --cov=west"
cmd = "python -m pytest -W error"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Do we need to lose the coverage options on this task?

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.

@pdgendt has proposed this change.
Maybe you missed it: This command is moved to uv run poe gh-test as those coverage files are most likely only needed in CI.
Do you see any benefit of creating the coverage files always on the user's local system on each uv run poe test?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Arguments passed on the CLI are still possible, it's just not generated by default.

$ uv run poe test --cov-report=html --cov-config=pyproject.toml --cov=west

I don't tend to look at coverage locally that often, so I like that it's now opt-in. We could provide a poe config option for it, but it's a bit overkill IMO.

@marc-hb
Copy link
Copy Markdown
Collaborator

marc-hb commented Nov 25, 2025

I know we don't have a lot of pull requests but for the record and for reviewers who only give a hand from time to time, don't forget to mention that this is a better alternative to #883 where relevant discussion already happened.

Enable pytest `pythonpath=src` by default to run tests against the local
worktree (e.g. when invoked via `poe test`).
An alternative task `poe gh-test` is added, which explicitly unsets
`pythonpath` in order to test the installed package (run in CI within
`uv` environment).
@pdgendt
Copy link
Copy Markdown
Collaborator

pdgendt commented Nov 28, 2025

@marc-hb any open comments here?

@pdgendt pdgendt merged commit 58f0bdb into zephyrproject-rtos:main Nov 28, 2025
27 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