Open mttbernardini opened 1 month ago
@mttbernardini In your case, try
pdm run pytest -p <subproj>
I personally use a shell script, under ./bin/pdm.sh
ls packages | xargs -I % sh -c "pdm ${@} -p packages/%"
Then all you need to do is: ./bin/pdm.sh run pytest
Hey @sinogermany, thanks for your suggestion. I tried as you mentioned, however running pdm
with the -p
switch fails to satisfy my premise:
Assuming we use a shared venv from the top-folder where pdm.lock is located
Running pdm run -p <subproj> pytest
(note: params order matters, otherwise -p
gets parsed by pytest
rather than pdm
) tells pdm
to create a venv under <subproj>/.venv
rather than using the top-level one (tested using v2.15.2).
So mostly my question boils down to: how to run tools through pdm
with their CWD being <subproj>
, but having pdm
use the top-level .venv
?
PS: I discovered you can also do pdm run pytest <subproj>/
and that will filter test discovery to the given directory only, however it will still use the top-level pyproject.toml
or pytest.ini
for configuration rather than <subproj>/pytest.ini
. That may be an acceptable tradeoff if there's nothing to override, and that's the direction I'm following at the moment.
Assuming we use a shared venv from the top-folder where
pdm.lock
is located, how would you setup tests withpytest
?My understanding is that each subproject would have its own unit tests under
<subproj>/tests
and pytest configuration be in<subproj>/pyproject.toml
.Then, what would be the idiomatic way to invoke
pytest
?pdm run pytest
at the subproject directory would attempt to create a new venv rather than re-using the top one, unless I manually create a.pdm-python
file to point to the same venv. Is there a way to automate this behaviour?pdm run pytest --rootdir=<subproj>/tests
doesn't seem to workIdeas?