I can't Go To Definition for pytest fixtures in Cursor (VS Code)
I am using Cursor. I cannot command-click into fixtures injected as parameters in my pytests. Command-clicking to any other variable, function, class works fine. I am working in a Django Ninja project.
@pytest.mark.django_db
def test_deleting_an_already_inactive_channel_raises_error(mock_auth, client, client_headers, user, channel):
channel.active = False
channel.save()
url = reverse("roon:channel", kwargs={"channel_id": channel.id})
response = client.delete(url, content_type="application/json", headers=client_headers(user))
assert response.status_code == HTTPStatus.UNPROCESSABLE_ENTITY
In the above example, I cannot click into mock_auth
, client
, client_headers
, etc.
Here is my VS Code settings.json
:
{
"python.testing.pytestEnabled": true,
"python.testing.pytestArgs": ["--import-mode=importlib", "--no-cov"]
}
Here is my pyproject.toml
:
[tool.pytest.ini_options]
minversion = "7.0"
#Pytest to have verbose outputs
#Pytest-xdist automatically determines number of workers based on cpu#Output a summary of all, except passes
#Pytest report stats - Failures + Skipped
#Pytest-cov to report coverage for library
#Pytest-cov to use pyproject.toml file for additional coverage config
#Pytest-cov outputs coverage to stdout
#Pytest-cov fails if the coverage falls under the value
#Pytest-cov generates an HTML report in /test-results
#Pytest-cov generates an XML report in /test-results
addopts = '''
-vv
-n auto
-ra
-m "not (deprecated or integration)"
--cov=api
--cov-config pyproject.toml
--cov-report term-missing
--cov-fail-under=60
--cov-report html
--cov-report xml
--durations=10
-s
'''
markers = [
"integration: marks tests for integration environment (deselect with '-m \"not integration\"')",
"slow: marks tests the are VERY slow (deselect with '-m \"not slow\"')",
"deprecated: marks tests the are deprecated or on an invalid version (deselect with '-m \"not deprecated\"')",
]
testpaths = [
"api",
"carespace"
]
python_files = ["test_*.py", "*_test.py", "tests.py"]
[tool.coverage.run]
parallel = true
branch = true
source = [
"api/*",
]
omit = [
"*/test/*",
"*/tests/*",
"*/migrations/*",
"*/management/*",
# Skip Admin pages
"*/admin*",
# Deprecated Apps
]
[tool.coverage.report]
show_missing = true
skip_covered = true
ignore_errors = true
sort = "Cover"
exclude_lines = [
"pragma: no cover",
# Don't complain about missing debug-only code:
"def __unicode__",
"def __repr__",
"if self.debug",
# Don't complain if tests don't hit defensive assertion code:
"raise AssertionError",
"raise NotImplementedError",
# Don't complain if non-runnable code isn't run:
"if 0:",
"if __name__ == .__main__.:",
"from",
]
[tool.coverage.html]
directory = "test-results/line_coverage_html"
[tool.coverage.xml]
output = "test-results/coverage.xml"
I tried the "configure tests" -> "pytests" -> "root directory" flow in VS Code.