CI good practice #13138
-
|
Hello, In my CI workflow, amongst others, I wish to test the following:
First question is: Second question is: Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 3 replies
-
|
Yes, it's the best practice to test as installed: https://blog.ganssle.io/articles/2019/08/test-as-installed.html. Different people do this differently, though. I've seen some just removing the locally importable thing. Others do Personally, I use a combination of these and even have an action for running tests from sdists instead of Git checkouts. Here's one of my recent examples: https://github.com/ansible/awx-plugins/tree/0d569b5/.github/workflows. Note that it takes a number of things to extremes and uses tox as a workflow tool (which is what I recommend for ensuring local runs are close to the CI). |
Beta Was this translation helpful? Give feedback.
-
|
One option is to use an |
Beta Was this translation helpful? Give feedback.
-
|
Thanks for both your answers and the reference! I do use separate "project" and "test" folders, with the pytest configuration [tool.pytest.ini_options]
testpaths = "test"I didn't realize that this meant that pytest was ran "from Thanks! |
Beta Was this translation helpful? Give feedback.
-
|
Thank you all for your answers. |
Beta Was this translation helpful? Give feedback.
@ego-thales that depends on a few factors:
when you run
python -m pytest, Python itself adds the current working directory toPYTHONPATH, while runningpytestdoes not do that (which is what you do, it seems — withuv run pytestand notuv run python -m pytest; it's notuvmagic).I like running
python -Im pytestto counteract that import path influence, while still being in control of what Python interpreter is being used.depending on whether you have an
__init__.pyin your tests directory, I thinkpytestauto-injects things intosys.pathtooWith that in mind, if you know what you're doing, you can trick it into one behavior or the other, and do it however you like, really.
OTOH,…