testcontainers / testcontainers/testcontainers-python

Allow option to keep the containers alive

Open
#109 18 comments 23 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

🐣 good first issue 🤝 contributions are welcome 🛟 help wanted
Dominant language
Python
Stars
2.3k
Forks
386
Avg merge
4h 40m
Merged PRs (30d)
1

Description

It would be nice to keep the docker containers alive for speeding up the test runs. Now, in every test run containers are re-created and can't keep them alive since this block

  def __del__(self):
        """
        Try to remove the container in all circumstances
        """
        if self._container is not None:
            try:
                self.stop()
            except:  # noqa: E722
                pass

removes containers when the instance variable is deleted (when the program terminates) and I cannot override it because this also runs without using with as block.

I don't want my Mysql container to be recreated everytime. I am running tests very frequently and I am waiting couple seconds everytime. Pretty annoying.

I can make a small PR if that makes sense?

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 reading testcontainers/core/container.py around the del method and trace how containers are stopped when a test run ends, including use outside a with block. Define the option's lifecycle behavior for both context-managed and directly created containers; done means a caller can keep a MySQL container alive across runs without automatic cleanup.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker, python
Domain
devops, testing
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.