pytest-dev / pytest-dev/pytest

pytest is leaving behind symlink'd directories in tmpdir

Open
#5,232 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

plugin: tmpdir type: enhancement
Dominant language
Python
Stars
14.5k
Forks
3.4k
Avg merge
2d 9h
Merged PRs (30d)
35

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the leftover symlinked directories with pytest's tmpdir_factory and tmpdir fixtures using the reported pytest 4.4.1 environment. Trace temporary-directory cleanup from those fixture entry points; done means session and test temporary data no longer leave the reported "current" symlinked directories behind.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
testing-qa
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.