pytest error when running tox

Created on 27 Jul 2018  路  6Comments  路  Source: pytest-dev/pytest

I get this error when running pytest:

py.error.ENOENT: [No such file or directory]: open('/Users/me/Github/the-package/.pytest_cache/v/cache/nodeids', 'w')

This is my tox.ini

[tox]
envlist = py36

[flake8]
max-line-length = 100

[testenv]
passenv = CUSTOM_PYPI_URL

setenv = ENVIRONMENT = DEVELOPMENT
                IGNORE_JWT_VALIDATION = True
                RABBITMQ_NOENCRYPT = false

whitelist_externals =
    bash
    python
    flake8
    coverage
    bandit

deps=-r{toxinidir}/test-requirements.txt

commands = flake8 the_package --doctests --exit-zero --count
           bandit -r the_package -lll
           coverage run --source the_package -m pytest
           coverage report

Using:

  • Python 3.6.4
  • OSX 10.12.6

  • pytest==3.6.3

  • tox==3.1.2
  • bandit==1.4.0
  • flake8==3.5.0
  • coverage==4.5.1

I haven't found any info online about this error, but what makes it confusing is, out of all our micro services that have identical tox commands (except the package name), this is the only one that throws this error :(

This is the code that causes the error:


        try:
            f = path.open("w")  # This is the problem (somehow)
        except py.error.ENOTDIR:
            self.config.warn(
                code="I9", message="cache could not write path %s" % (path,)
            )
        else:
            with f:
                self.trace("cache-write %s: %r" % (key, value))
                json.dump(value, f, indent=2, sort_keys=True)
bug

Most helpful comment

ah yeah that would do it! we have some ~rough plans to have better isolation from mocked modules but haven't done anything to solve it yet.

Thanks for the issue nonetheless!

All 6 comments

GitMate.io thinks possibly related issues are https://github.com/pytest-dev/pytest/issues/3112 (Key errors while running pytest), https://github.com/pytest-dev/pytest/issues/2777 (pytest is not running when i run it through tox -- Mac), https://github.com/pytest-dev/pytest/issues/3326 (tox and pytest runs can behave differently when "-p something.conftest" is specified), https://github.com/pytest-dev/pytest/issues/1591 (pytest-xdist fails when running same tests several times), and https://github.com/pytest-dev/pytest/issues/3097 ("unrecognized arguments" or "option names already added" error when running pytest inside a Docker container using Jenkins).

Could you share the package name? Also let's see if we can't factor out tox, does .tox/py36/bin/python -m pytest reproduce this issue?

Also curious what tree .pytest_cache looks like (or any other recursive view of that directory)

Regardless of the investigation and possible workaround, I think we should catch IOError and OSError in that section of code instead of only ENOTDIR; cache is secondary, so it should not blow up the test suite IMO.

@asottile running .tox/py36/bin/python -m pytest produces the same error

I should probably explain this better,
We have a standard circle config across all our services, and .pytest_cache is part of the .gitignore we use for all of them. CircleCI hasn't cared up until this point, it just runs the tests an moves on.
With this particular one however, dhos_pdf_adapter_worker, CircleCI was throwing this error.
In order to recreate this issue, i removed all the excluded files (including .pytest_cache) by getting a fresh clone, ran tox and got the same error. I have tried this with other repos too and just can't recreate it.

@asottile You know what? I owe you an apology, turns out I had done some dodgy mocking screwed up the os package. sorry for wasting your time.

ah yeah that would do it! we have some ~rough plans to have better isolation from mocked modules but haven't done anything to solve it yet.

Thanks for the issue nonetheless!

Was this page helpful?
0 / 5 - 0 ratings