Wrong path referenced for failing test
See original GitHub issueI locally moved my project folder project/ to another directory from /files/old/path/project to /files/new/project. Then, I ran the tests with pytest, which works as expected - except the shown path to a test file when a test fails [output is censored]:
E AssertionError: assert 'something' == <something_else'>
E - something
E ? ^^
E + something_else
E ? ^^^
/files/old/path/project/tests/test_something.py:30: AssertionError
When I run pytest --vvv, I get:
project/tests/test_something.py::TestName::test_something[SUCCESS-something] <- ../../project/tests/test_something.py FAILED [ 25%]
which shows the relative path to the old directory.
Expected behavior: The old directory is not shown anywhere.
pyproject.toml:
[tool.pytest.ini_options]
minversion = "7.1.2"
addopts = "--cov=app/ --cov-report html --cov-report term"
testpaths = [
"tests"
]
required_plugins = ["pytest-cov", "pytest-mock"]
pythonpath = ["app"]
Setup on macOS 12.5 (M1):
platform darwin -- Python 3.9.7, pytest-7.1.2, pluggy-1.0.0 -- /Users/name/miniforge3/envs/env-name/bin/python3.9
cachedir: .pytest_cache
django: settings: backend.server.settings (from ini)
rootdir: /files/new/, configfile: pyproject.toml, testpaths: project/tests
plugins: anyio-3.5.0, env-0.6.2, dash-2.5.0, mock-3.8.2, django-4.5.2, cov-3.0.0
Issue Analytics
- State:
- Created a year ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
catching wrong path in JUnit - Stack Overflow
I want to create a test case for below code but it gives always this error ... on project 481.demo.child: Compilation failure [ERROR] ......
Read more >Test-Path - PowerShell - Microsoft Learn
The Test-Path cmdlet determines whether all elements of the path exist. It returns $True if all elements exist and $False if any are...
Read more >Error Messages | Cypress Documentation
This message means that Cypress was unable to find tests in the specified file. You'll likely get this message if you have an...
Read more >unittest — Unit testing framework — Python 3.11.1 ...
The path is converted to a module name by removing the '.py' and ... Output is echoed normally on test fail or error...
Read more >Testing Python in Visual Studio Code
Because the test failure can easily be traced to a particular code change, it's easy to find and remedy the cause of the...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Pretty sure that’s what happened, stale
.pycfiles, especially if it just went away after awhile.Closing this for now then. 👍
Did you possibly rename the complete folder, pyc files cache the initial filename, so a stale byte code cache Could be a reason
Are any pytest options in use that may prevent the mismatch error that’s supposed to happen then