Skip to content

Commit b91ebe6

Browse files
authored
Merge pull request pytest-docker-compose#25 from RmStorm/develop
Added option to remove volumes after running tests this closes pytest-docker-compose#23
2 parents 140c2c7 + 350a507 commit b91ebe6

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

README.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,16 @@ working directory. You can specify a different file via the
181181
See `Configuration Options`_ for more information on using configuration
182182
files to modify pytest behavior.
183183

184+
Remove volumes after tests
185+
--------------------------
186+
There is another configuration option that will delete the volumes of containers after running.
187+
188+
.. code-block:: sh
189+
190+
pytest --docker-compose-remove-volumes
191+
192+
This option will be ignored if the plugin is not used. Again, this option can also be added to the pytest.ini file.
193+
184194
For more examples on how to use this plugin look at the testing suite of this plugin itself! It will give you some examples for configuring pytest.ini and how to use the different fixtures to run docker containers.
185195

186196
.. _Configuration Options: https://docs.pytest.org/en/latest/customize.html#adding-default-options

src/pytest_docker_compose/__init__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ def pytest_addoption(parser):
7878
help="Path to docker-compose.yml file, or directory containing same.",
7979
)
8080

81+
group.addoption("--docker-compose-remove-volumes", action="store_true",
82+
default=False, help="Remove docker container volumes after tests")
83+
8184
group.addoption("--docker-compose-no-build", action="store_true",
8285
default=False, help="Boolean to not build docker containers")
8386

@@ -173,7 +176,8 @@ def scoped_containers_fixture(docker_project: Project, request):
173176
or "(no logs)", '\n')
174177

175178
if not request.config.getoption("--use-running-containers"):
176-
docker_project.down(ImageType.none, False)
179+
docker_project.down(ImageType.none, request.config.getoption("--docker-compose-remove-volumes"))
180+
177181
scoped_containers_fixture.__wrapped__.__doc__ = """
178182
Spins up the containers for the Docker project and returns an
179183
object that can retrieve the containers. The returned containers

0 commit comments

Comments
 (0)