Sharing containers across test cases in a test module and cleanup the containers at the end

Open
#1,004 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
38/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Active
Tech stack
docker, rust
Domain
testing

Research direction

The issue names no source files or tests. Start by reading the crate’s container lifecycle and test support, then check what cleanup hooks cargo/libtest exposes for test modules. Done means there is a way to share containers across cases and clean them up when the module’s tests finish, without relying on reusable containers.

Written by the indexing model from the issue text.

Description

Is there a way to share containers across a test module and have the containers cleaned up at the end of the test module execution?

Starting and stopping these containers takes time, so I prefer sharing them and making sure my test cases don't interfere with one another.

For now I am using a LazyLock to share containers across test cases, but I don't manage to clean them up at the end of the run. Unfortunately cargo/libtest, don't provide 'AfterAll' hooks I can register the cleanup in and static state is not dropped when the module finishes testing.

I don't want to rely on the reusable testcontainers feature as these typically remain running after the test module execution.

Dominant language
Rust
Stars
1.1k
Forks
206
PR merge metrics
No merged PRs in 30d

Getting set up

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.

More from testcontainers/testcontainers-rs

All issues in testcontainers/testcontainers-rs

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.