pytest-dev/pytest-splinter

Direct use of 'tmpdir' fixture causes warnings to be raised in latest pytest versions

jsfehler opened this issue ยท 11 comments

The following warning message appears after test runs:

RemovedInPytest4Warning: Fixture "tmpdir" called directly. Fixtures are not meant to be called directly, are created automatically when test functions request them as parameters. See https://docs.pytest.org/en/latest/fixture.html for more information.

The offending line is:

from _pytest.tmpdir import tmpdir

Simple fix would be reimplementing the function pytest uses to create tmpdir:

def _mk_tmp(request, factory):
    name = request.node.name
    name = re.sub(r"[\W]", "_", name)
    MAXVAL = 30
    name = name[:MAXVAL]
    return factory.mktemp(name, numbered=True)

@pytest.fixture(scope='session')
def session_tmpdir(request, tmpdir_factory):
    """pytest tmpdir which is session-scoped."""
    return _mk_tmp(request, tmpdir_factory)

Another path would be getting pytest to implement a session_tmpdir fixture.

Because of an interaction between the warning and pytest this causes all tests to error out. Thanks @jsfehler I've copied that code into my project's conftest to remove the failures from the warning and now my suite passes again.

@youtux Are you working on something different/better for this issue? If not, I can open a PR with these changes.

I already started working on that, but I got preempted. I think by this weekend I will come up with a PR.

any update on this ?

There is an open PR at #116, but it has not been reviewed yet. I will ping the pytest-dev group again.

any progress on the issue? with pytest version 4 pytest-splinter is simply broken because of this issue...

@youtux thanks for the fix. I've also hit this bug today with clean pip install pytest-splinter.

... also, I know it's been only 23 hours since you committed the fix but... how about a release? :-) Thanks.

I am getting this

request = <SubRequest 'session_tmpdir' for >
factory = TempdirFactory(_tmppath_factory=TempPathFactory(_given_basetemp=None, _trace=<pluggy._tracing.TagTracerSub object at 0x0000017C54111978>, _basetemp=None))

def _mk_tmp(request, factory):
    name = request.node.name
  name = re.sub(r"[\W]", "_", name)

E NameError: name 're' is not defined

@KevMuriithi can you post the full stack trace? Also the version of python, pytest and pytest-splinter you are using

@mpasternak I just release version 2.0.1 on PyPI. Happy testing!