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

pytest is leaving behind symlink'd directories in tmpdir #5232

Open
markmelvin opened this issue May 8, 2019 · 7 comments
Open

pytest is leaving behind symlink'd directories in tmpdir #5232

markmelvin opened this issue May 8, 2019 · 7 comments
Labels
plugin: tmpdir related to the tmpdir builtin plugin type: enhancement new feature or API change, should be merged into features branch

Comments

@markmelvin
Copy link

markmelvin commented May 8, 2019

My regression tests are leaving behind a symlink'd folder ending in "current" for every test executed. This ends up publishing duplicate folders as artifacts into my CI system. From what I have seen these folders should be cleaned up by pytest automatically, no?

I'm using the tmpdir_factory fixture in various session-level fixtures, and tmpdir in various tests to create files in the temp folder like so:

@pytest.fixture(scope='session')
def some_session_level_fixture(tmpdir_factory):
    some_file = os.path.join(tmpdir_factory.getbasetemp(), 'some_file')
    with open(some_file, 'w') as f:
          ...do stuff

And

def some_test(tmpdir):
    some_file = os.path.join(tmpdir, 'some_file')
    with open(some_file, 'w') as f:
          ...do stuff

It does this on both Python 3.5 and 3.7 on both Ubuntu Linux 16.04 and 19.04. I am running pytest via pipenv and My pipenv environment looks like this:

boto3==1.9.140
  - botocore [required: >=1.12.140,<1.13.0, installed: 1.12.140]
    - docutils [required: >=0.10, installed: 0.14]
    - jmespath [required: >=0.7.1,<1.0.0, installed: 0.9.4]
    - python-dateutil [required: >=2.1,<3.0.0, installed: 2.8.0]
      - six [required: >=1.5, installed: 1.12.0]
    - urllib3 [required: >=1.20,<1.25, installed: 1.24.3]
  - jmespath [required: >=0.7.1,<1.0.0, installed: 0.9.4]
  - s3transfer [required: >=0.2.0,<0.3.0, installed: 0.2.0]
    - botocore [required: >=1.12.36,<2.0.0, installed: 1.12.140]
      - docutils [required: >=0.10, installed: 0.14]
      - jmespath [required: >=0.7.1,<1.0.0, installed: 0.9.4]
      - python-dateutil [required: >=2.1,<3.0.0, installed: 2.8.0]
        - six [required: >=1.5, installed: 1.12.0]
      - urllib3 [required: >=1.20,<1.25, installed: 1.24.3]
matplotlib==3.0.3
  - cycler [required: >=0.10, installed: 0.10.0]
    - six [required: Any, installed: 1.12.0]
  - kiwisolver [required: >=1.0.1, installed: 1.1.0]
    - setuptools [required: Any, installed: 41.0.1]
  - numpy [required: >=1.10.0, installed: 1.16.3]
  - pyparsing [required: >=2.0.1,!=2.1.6,!=2.1.2,!=2.0.4, installed: 2.4.0]
  - python-dateutil [required: >=2.1, installed: 2.8.0]
    - six [required: >=1.5, installed: 1.12.0]
paho-mqtt==1.4.0
paramiko==2.4.2
  - bcrypt [required: >=3.1.3, installed: 3.1.6]
    - cffi [required: >=1.1, installed: 1.12.3]
      - pycparser [required: Any, installed: 2.19]
    - six [required: >=1.4.1, installed: 1.12.0]
  - cryptography [required: >=1.5, installed: 2.6.1]
    - asn1crypto [required: >=0.21.0, installed: 0.24.0]
    - cffi [required: >=1.8,!=1.11.3, installed: 1.12.3]
      - pycparser [required: Any, installed: 2.19]
    - six [required: >=1.4.1, installed: 1.12.0]
  - pyasn1 [required: >=0.1.7, installed: 0.4.5]
  - pynacl [required: >=1.0.1, installed: 1.3.0]
    - cffi [required: >=1.4.1, installed: 1.12.3]
      - pycparser [required: Any, installed: 2.19]
    - six [required: Any, installed: 1.12.0]
pytest==4.4.1
  - atomicwrites [required: >=1.0, installed: 1.3.0]
  - attrs [required: >=17.4.0, installed: 19.1.0]
  - more-itertools [required: >=4.0.0, installed: 7.0.0]
  - pluggy [required: >=0.9, installed: 0.9.0]
  - py [required: >=1.5.0, installed: 1.8.0]
  - setuptools [required: Any, installed: 41.0.1]
  - six [required: >=1.10.0, installed: 1.12.0]
requests==2.21.0
  - certifi [required: >=2017.4.17, installed: 2019.3.9]
  - chardet [required: >=3.0.2,<3.1.0, installed: 3.0.4]
  - idna [required: >=2.5,<2.9, installed: 2.8]
  - urllib3 [required: >=1.21.1,<1.25, installed: 1.24.3]
websockets==7.0
@markmelvin markmelvin changed the title pipenv is leaving behind symlink'd directories in tmpdir pytest is leaving behind symlink'd directories in tmpdir May 9, 2019
@markmelvin
Copy link
Author

Updated title (oops)

@markmelvin
Copy link
Author

I've narrowed this down to the simplest test case. This test.py file:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import logging
import pytest

def test_one(tmpdir):
    logging.getLogger().info(tmpdir)

leaves two folders in the temp directory:

  • test_one0
  • test_onecurrent

The latter being a symlink to the first. How do I get rid of the crufty symlink'd folders?

@RonnyPfannschmidt
Copy link
Member

currently not, but its fixable

@RonnyPfannschmidt
Copy link
Member

_force_symlink(root, prefix + "current", new_path)
needs a opt-out that then is to be used for the tmpdir fixture

@markmelvin
Copy link
Author

Thanks. What about just cleaning up symlinks that pytest created on exit? I suppose I could just do that in my test code too...

@nicoddemus
Copy link
Member

@RonnyPfannschmidt I know this is historical, but do you remember why pytest creates that symlink?

Regardless, how about if we remove the symlink when pytest exits, as @markmelvin proposes?

@nicoddemus nicoddemus added plugin: tmpdir related to the tmpdir builtin plugin type: enhancement new feature or API change, should be merged into features branch labels May 9, 2019
@RonnyPfannschmidt
Copy link
Member

@nicoddemus the symlink was always a courtesy to enable quickly finding the current test/current basetemp even after pytest exited

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
plugin: tmpdir related to the tmpdir builtin plugin type: enhancement new feature or API change, should be merged into features branch
Projects
None yet
Development

No branches or pull requests

3 participants