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

Confusing error message around tmpdir fixture #1098

Closed
asottile opened this issue Oct 1, 2015 · 2 comments
Closed

Confusing error message around tmpdir fixture #1098

asottile opened this issue Oct 1, 2015 · 2 comments
Labels
topic: reporting related to terminal output and user-facing messages and errors

Comments

@asottile
Copy link
Member

asottile commented Oct 1, 2015

Simplest reproduction:

import pytest

@pytest.yield_fixture
def tmpdir_factory(tmpdir):
    yield

def test_1(tmpdir):
    pass
$ py.test test.py
============================= test session starts ==============================
platform linux2 -- Python 2.7.6, pytest-2.8.1, py-1.4.30, pluggy-0.3.1
rootdir: /tmp, inifile: 
collected 1 items 

test.py E

==================================== ERRORS ====================================
___________________________ ERROR at setup of test_1 ___________________________
file /tmp/test.py, line 7
  def test_1(tmpdir):
file /tmp/venv/local/lib/python2.7/site-packages/_pytest/tmpdir.py, line 109
  @pytest.fixture
  def tmpdir(request, tmpdir_factory):
file /tmp/test.py, line 3
  @pytest.yield_fixture
  def tmpdir_factory(tmpdir):
        fixture 'tmpdir' not found
        available fixtures: tmpdir_factory, pytestconfig, cache, recwarn, monkeypatch, record_xml_property, capfd, capsys, tmpdir
        use 'py.test --fixtures [testpath]' for help on them.

/tmp/test.py:3
=========================== 1 error in 0.01 seconds ============================

pytest version: 2.8.1

fwiw this breaks my build here: https://travis-ci.org/pre-commit/pre-commit/jobs/83034637

@nicoddemus
Copy link
Member

Thanks the report!

The problem is that a new tmpdir_factory was introduced in 2.8 as a builtin fixture, and your fixture is overriding it here because it has the same name. Your fixture uses tmpdir, and the problem is that the builtin tmpdir fixture now requires tmpdir_factory (the builtin), but your fixture overwrote the builtin with your own (which requires tmpdir) hence there's a recursion.

The workaround is to rename your tmpdir_factory fixture to something else, I'm afraid (looking at your code perhaps you can replace your tmpdir_factory implementation with pytest's, they have the same purpose albeit slightly different interfaces).

Not sure how simple it is to fix this in pytest to at least produce a better message, though.

@nicoddemus nicoddemus added the topic: reporting related to terminal output and user-facing messages and errors label Oct 1, 2015
@nicoddemus
Copy link
Member

I see you renamed your fixture to tmpdir_factory in pre-commit/pre-commit#270, so I'm closing this for now. 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: reporting related to terminal output and user-facing messages and errors
Projects
None yet
Development

No branches or pull requests

2 participants