question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Wrong path referenced for failing test

See original GitHub issue

I 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:closed
  • Created a year ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
nicoddemuscommented, Jul 25, 2022

I locally moved my project folder project/ to another directory from /files/old/path/project to /files/new/project. Did you possibly rename the complete folder, pyc files cache the initial filename, so a stale byte code cache Could be a reason

Pretty sure that’s what happened, stale .pyc files, especially if it just went away after awhile.

Closing this for now then. 👍

1reaction
RonnyPfannschmidtcommented, Jul 25, 2022

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found