Pytest: Run pytest on read-only file systems

Created on 9 Jun 2018  路  13Comments  路  Source: pytest-dev/pytest

Follow up to: https://github.com/pytest-dev/pytest/issues/200#issuecomment-395967759

I propose:

  • Instead of failing, the cache plugin should emit a warning in the pytest header instead of "cachedir:" entry stating that it could not create the cache dir.
  • PYTHONDONTWRITEBYTECODE should not be necessary, we should just skip creating __pycache__ directories and writing rewritten .pyc files in this case.
mac enhancement proposal

Most helpful comment

IIRC -o cache_dir=/dev/null helps to work around this currently.

For me this results in (BTW running in a Docker container):

=============================== warnings summary ===============================
<undetermined location>
  could not create cache path /dev/null/v/cache/nodeids

So just have to use /var/tmp or something if you need to get it out of CWD.

Edit: Or, not mentioned here, but mentioned on #200 and what I was looking-for (way of explicitly disabling .pytest_cache: use -p no:cacheprovider.

All 13 comments

GitMate.io thinks possibly related issues are https://github.com/pytest-dev/pytest/issues/3556 ([Question] Can I run pytest on a read-only filesystem?), https://github.com/pytest-dev/pytest/issues/471 (pytest keeps running deleted tests), https://github.com/pytest-dev/pytest/issues/2783 (pytest running pyximport?), https://github.com/pytest-dev/pytest/issues/1110 (Pytest fails if run from inside a function), and https://github.com/pytest-dev/pytest/issues/401 (Reduce pytest's overhead for running tests).

Makes sense to me.
IIRC -o cache_dir=/dev/null helps to work around this currently.

Some related issues:

  • #3556
  • #1029

As far as I can tell, this is already satisfied.

I set up this directory structure:

$ find -name "*.py" | xargs tail -n999
==> ./wat.py <==
def f():
    return 1

==> ./tests/__init__.py <==

==> ./tests/wat_test.py <==
from wat import f


def test_f():
    assert f() == 1

Then did

chmod -R -w .

And this is the output of pytest:

$ pytest tests
============================= test session starts ==============================
platform linux -- Python 3.6.5, pytest-3.6.1, py-1.5.3, pluggy-0.6.0
rootdir: /tmp/t/repo, inifile:
collected 1 item                                                               

tests/wat_test.py .                                                      [100%]

=============================== warnings summary ===============================
None
  could not create cache path /tmp/t/repo/.pytest_cache/v/cache/nodeids

-- Docs: http://doc.pytest.org/en/latest/warnings.html
===================== 1 passed, 1 warnings in 0.01 seconds =====================

The warning message is _a bit weird_ (None?), but otherwise looks like everything is in order.

Seems a tiny type error here:

https://github.com/pytest-dev/pytest/blob/80f8a3ad7caee37e714a3e165318061e58eccc1c/src/_pytest/terminal.py#L685

I'll take a stab at a fix, should be pretty easy (but again, orthogonal to this issue which seems "already fixed")

3563 addresses the warnings messaging

Thanks @asottile! 馃憤

I created this mostly because it seems people still have issues with it.

Let's try to direct new issues to this thread and reopen it as needed if we find something still lacking.

Closing this then.

I am on Windows.. running with

import sys, sys.dont_write_bytecode = True.

running the tests in ipython using

%run -m pytest -s pkg/tests/test_module.py

What I am finding is that if I startup ipython and run the test, it works fine. But then if I try to run it a second time in the same ipython session it fails.

Any idea why this might be happening? My first hypothesis was that this was because the cache is not being cleared... but I do have the dont_write_bytecode switch on..

%run -m pytest will start a new process. setting sys.dont_write_bytecode is only going to modify the setting inside the ipython process

@asottile, Thanks.. I see.. That actually makes senses that %run -m pytest start up another python process..I have seen this kind of failure before.. but it was intermittent.. but now it happens everytime very repeatably..

What additional arguments should I pass so as to not generate the cache when running something like %run -m pytest on Windows systems?

@blueyed pointed out -o /dev/null, but there is no /dev/null on windows systesm..

on windows nul is ~= /dev/null

setting os.environ['PYTHONDONTWRITEBYTECODE'] = '1' should get inherited by the subprocess if you want to use %run

IIRC -o cache_dir=/dev/null helps to work around this currently.

For me this results in (BTW running in a Docker container):

=============================== warnings summary ===============================
<undetermined location>
  could not create cache path /dev/null/v/cache/nodeids

So just have to use /var/tmp or something if you need to get it out of CWD.

Edit: Or, not mentioned here, but mentioned on #200 and what I was looking-for (way of explicitly disabling .pytest_cache: use -p no:cacheprovider.

Was this page helpful?
0 / 5 - 0 ratings