Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

tmpdir_factory deletes tmp dirs from other pytest processes after 3 hours, even if they are still running #7911

Copy link
Copy link
@danc86

Description

@danc86
Issue body actions

We use pytest in a Jenkins job, which ends running many concurrent pytest processes on a single Linux worker under the same user account (jenkins). The test suite has some session-scoped fixtures which use tmpdir_factory to create temporary directories and create files in them, which are then used throughout the duration of the entire test run.

Recently our pytest runs started taking longer than 3 hours and we started to see tests randomly fail near the end of the suite with errors like this:

FileNotFoundError: [Errno 2] No such file or directory: '/tmp/pytest-of-jenkins/pytest-47927/...

indicating that something had deleted the tmp files created by the session-scoped fixture at the beginning of the test run.

Pytest's tmpdir_factory fixture calls make_numbered_dir_with_cleanup to handle creation and cleanup of tmp directories:
https://github.com/pytest-dev/pytest/blob/4.4.0/src/_pytest/tmpdir.py#L75
That function has some logic which looks for the presence of a lock file to detect if the directory is still being used by another pytest process:
https://github.com/pytest-dev/pytest/blob/4.4.0/src/_pytest/pathlib.py#L205
but the logic assumes that any lock file older than the given "lock timeout" (hardcoded to 3 hours) is stale and can just be deleted. But if the other pytest process is actually still running after 3 hours, its tmp directory will be deleted while it is still in use.

The Linux worker is CentOS 7.8 with Python 3.6.8 and pytest 4.4.0. I see the pytest master branch still has the same 3 hour timeout logic so I think this bug will affect all recent versions of pytest.

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issueeasy issue that is friendly to new contributoreasy issue that is friendly to new contributorplugin: tmpdirrelated to the tmpdir builtin pluginrelated to the tmpdir builtin pluginstatus: help wanteddevelopers would like help from experts on this topicdevelopers would like help from experts on this topictype: bugproblem that needs to be addressedproblem that needs to be addressed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.