Open EdmundsEcho opened 1 week ago
You'll probably need to define a build system so your project is installed in the environment and discoverable by pytest.
Thank you for the response. The link was helpful.
In the meantime, the following gets pytest
to run from the project root:
set -x PYTHONPATH .; uv run pytest
Interestingly, ruff
seems to resolve the dependency without the env setting.
It's possible that https://docs.pytest.org/en/stable/explanation/goodpractices.html could help here, they have a section for your case: Tests as part of application code
I did some more reading here, and your case should work with:
❯ uv run -m pytest
or
❯ touch tests/__init__.py
❯ uv run pytest --pyargs my_module
as described in the pytest documentation.
@zanieb Thank you!!
What you provided is definitely worth including in the documentation that describes setting up an application with uv
.
Even better, it may be worthwhile to include a init command that includes the file structure for testing hello.py
("It works!"). This would require having an opinion on the file structure... which is good. I believe the structure that I set-up is a solid, straightforward norm, but I actually don't care :-)) What I mean by that is that whatever uv
chooses to go with, I would go with... I want to build and setup quickly, including tests (just like rust, which includes a unit test in the initialized app).
The problem is that, in Rust, there's a standardized test runner. In Python, there is not. We'd get complaints if we configured the project with pytest by default, though maybe we should anyway.
@zanieb My take on this is that anyone with a POV has what they need (expertise) to make the change to how they like it. The goal of uv
is to get a person up and running.
had same issue where pytest
couldn't find the package after converting from poetry
to uv
fixed by adding this to pyproject.toml
:
[build-system]
requires = ['setuptools']
build-backend = 'setuptools.build_meta'
My project structure is:
The
test_parser.py
references the module:I can build and run the parser but I cannot seem to get
uv run pytest
to run without getting a module not found error.Apologies for the hyper newby question here.