Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run pytest on read-only file systems #3557

Closed
nicoddemus opened this issue Jun 9, 2018 · 13 comments
Closed

Run pytest on read-only file systems #3557

nicoddemus opened this issue Jun 9, 2018 · 13 comments
Labels
platform: mac mac platform-specific problem type: enhancement new feature or API change, should be merged into features branch type: proposal proposal for a new feature, often to gather opinions or design the API around the new feature

Comments

@nicoddemus
Copy link
Member

Follow up to: #200 (comment)

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.
@nicoddemus
Copy link
Member Author

In fact the last point seems to be covered already:

elif e in [errno.EACCES, errno.EROFS, errno.EPERM]:
state.trace("read only directory: %r" % fn_pypath.dirname)
write = False

@nicoddemus nicoddemus added type: enhancement new feature or API change, should be merged into features branch type: proposal proposal for a new feature, often to gather opinions or design the API around the new feature labels Jun 9, 2018
@pytestbot
Copy link
Contributor

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

@blueyed
Copy link
Contributor

blueyed commented Jun 9, 2018

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

@asottile
Copy link
Member

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.

@asottile
Copy link
Member

Seems a tiny type error here:

self._tw.line(str(location) or "<undetermined location>")

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

@asottile
Copy link
Member

#3563 addresses the warnings messaging

@nicoddemus
Copy link
Member Author

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.

@alphaCTzo7G
Copy link

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

@asottile
Copy link
Member

asottile commented Jul 9, 2018

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

@alphaCTzo7G
Copy link

alphaCTzo7G commented Jul 10, 2018

@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..

@asottile
Copy link
Member

on windows nul is ~= /dev/null

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

@javabrett
Copy link

javabrett commented Jul 24, 2018

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.

aaron-junot added a commit to OperationCode/resources_api that referenced this issue Oct 9, 2020
* Add non-root user for running uwsgi in Dockerfile

* Fix PermissionError due to COPY after chown

* Bump flake8 from 3.8.3 to 3.8.4

Bumps [flake8](https://gitlab.com/pycqa/flake8) from 3.8.3 to 3.8.4.
- [Release notes](https://gitlab.com/pycqa/flake8/tags)
- [Commits](https://gitlab.com/pycqa/flake8/compare/3.8.3...3.8.4)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

* Bump pytest from 6.1.0 to 6.1.1

Bumps [pytest](https://github.com/pytest-dev/pytest) from 6.1.0 to 6.1.1.
- [Release notes](https://github.com/pytest-dev/pytest/releases)
- [Changelog](https://github.com/pytest-dev/pytest/blob/master/CHANGELOG.rst)
- [Commits](pytest-dev/pytest@6.1.0...6.1.1)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

* Remove log directory creation (#391)

* Remove log directory creation

* Remove unused import

* Remove rate limiting for now

* Fix volume permission overwrite

This problem seems to be already known in
docker/compose#3270 (comment)

* Fix duplicate root mkdir

* Disable pytest test caching

See pytest-dev/pytest#3557

* Add blank coverage file

* Added extra overriding of permissions command in CI config

* Added user UID

* Clean Dockerfile and revert pytest.ini

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
Co-authored-by: Aaron Suarez <aaron.j.suarez1@gmail.com>
Co-authored-by: Abdelrahman Kandil <abdelrahmankandil@hotmail.com>
Co-authored-by: Aaron Suarez <aaron-suarez@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
platform: mac mac platform-specific problem type: enhancement new feature or API change, should be merged into features branch type: proposal proposal for a new feature, often to gather opinions or design the API around the new feature
Projects
None yet
Development

No branches or pull requests

6 participants