Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pipenv pytest ignores source changes or uses cached source?

I have a Django 4.0.6 project, Python 3.9.15, Ubuntu 22.10, pipenv 2022.10.25, pytest 7.1.2

The test output was cached somewhere and now any modification is ignored unless I delete the method.

The steps I performed:

  1. Run the test: pipenv run pytest src/some/path/models.py
  2. The test fails, showing the correct error in traceback.
  3. Modify the method body.
  4. Run the test again.
  5. The test fails again, BUT the traceback shows old code, unmodified.

screen

Removing the method solves the problem, but any modification made to the method source makes it appear again in traceback, UNMODIFIED.

Does pipenv/pytest/whatever cache the source somewhere?

pipenv run pytest src/some/path/models.py --cache-clear did not help.

As well as removing the .pytest_cache/.

I tried removing the venv/some/path/__pycache__/models.cpython-39.pyc file (and all compiled *.pyc files in venv)

But nothing seem to help. The same traceback appears every time I run tests.

like image 995
rkardashov Avatar asked Jun 23 '26 00:06

rkardashov


1 Answers

Had the same issue and figured it out - the pytest i was running via pipenv run pytest ... was not actually part of the venv. I recommend you run it as pipenv run python -m pytest ...

like image 59
Vetsin Avatar answered Jun 27 '26 20:06

Vetsin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!