Skip to content

Possible race with parallel execution #232

@thrix

Description

@thrix

Thanks for creating this awesome pytest plugin!

We are running into ocassionally errors like this when testing with pytest-container in parallel in the tmt project:

plugins: xdist-3.6.1, testinfra-10.1.1, pytest_container-0.4.2, anyio-3.7.1
created: 4/4 workers
4 workers [267 items]
....
/tmp/tmp.brJePL3Qbj/lib64/python3.12/site-packages/pytest_container/container.py:1074: in launch_container
    release_lock()
        lock       = <filelock._unix.UnixFileLock object at 0x7f4aa7d048c0>
        release_lock = <function ContainerLauncher.launch_container.<locals>.release_lock at 0x7f4aa7c3ec00>
        self       = ContainerLauncher(container=Container(url='localhost/tmt/tests/container/fedora/40/upstream:latest',
                                      container_id='',
                                      entry_point=<EntrypointSelection.AUTO: 1>,
                                      custom_entry_point=None,
                                      extra_launch_args=[],
                                      extra_entrypoint_args=[],
                                      healthcheck_timeout=None,
                                      extra_environment_variables=None,
                                      singleton=False,
                                      forwarded_ports=[],
                                      volume_mounts=[],
                                      _is_local=True),
                  container_runtime=PodmanRuntime(build_command=['buildah',
                                                                 'bud',
                                                                 '--layers',
                                                                 '--force-rm'],
                                                  runner_binary='podman',
                                                  _runtime_functional=True),
                  rootdir=PosixPath('/var/ARTIFACTS/work-extended-unit-testsbq0eoa5c/plans/features/extended-unit-tests/discover/default-0/tests'),
                  extra_build_args=[],
                  extra_run_args=['--label',
                                  'pytest_container.request=<SubRequest '
                                  "'container' for <Function "
                                  'test_install_nonexistent[localhost/tmt/tests/container/fedora/40/upstream:latest '
                                  '/ dnf]>>',
                                  '--label',
                                  'pytest_container.node.name=test_install_nonexistent[localhost/tmt/tests/container/fedora/40/upstream:latest '
                                  '/ dnf]',
                                  '--label',
                                  'pytest_container.scope=function',
                                  '--label',
                                  'pytest_container.path=/var/ARTIFACTS/work-extended-unit-testsbq0eoa5c/plans/features/extended-unit-tests/discover/default-0/tests/tests/unit/test_package_managers.py'],
                  container_name='',
                  _expose_ports=True,
                  _new_port_forwards=[],
                  _container_id=None,
                  _stack=<contextlib.ExitStack object at 0x7f4aa7d04d10>,
                  _cidfile='/tmp/9ff87fff-a83f-4d73-9eb8-0489bcbfc126')
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

    def release_lock() -> None:
        _logger.debug("Releasing lock %s", lock.lock_file)
        lock.release()
>       os.unlink(lock.lock_file)
E       FileNotFoundError: [Errno 2] No such file or directory: '/tmp/15a4eab94d676c16ac9314f4e1e336d1.lock'

lock       = <filelock._unix.UnixFileLock object at 0x7f4aa7d048c0>

/tmp/tmp.brJePL3Qbj/lib64/python3.12/site-packages/pytest_container/container.py:1056: FileNotFoundError

Full logs here:

https://artifacts.dev.testing-farm.io/c003ad12-df6f-41df-abe7-55f857ca2d16/work-extended-unit-testsbq0eoa5c/plans/features/extended-unit-tests/execute/data/guest/default-0/tests/unit/with-system-packages/extended-1/output.txt

@dcermak aware of any issue around parallelization?

Anyway, we plan to debug it more, and hopefully provide a patch, wanted just to share our experience.

FTR the unit tests are here:

https://github.com/teemtee/tmt/blob/main/tests/unit/test_package_managers.py

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions