uvicorn works because python -m-style startup puts the current directory on sys.path. The pytest command doesn't. Tell pytest in config:
# pyproject.toml
[tool.pytest.ini_options]
pythonpath = ["."]
testpaths = ["tests"]Or run it as python -m pytest, which puts the cwd on the path the same way.
Delete the sys.path lines after that.