Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

limit services started by docker_services #54

Closed
adityaguru149 opened this issue Sep 19, 2020 · 7 comments
Closed

limit services started by docker_services #54

adityaguru149 opened this issue Sep 19, 2020 · 7 comments

Comments

@adityaguru149
Copy link

docker_services fixture starts all containers mentioned in the docker-compose.yaml.
Is there some way to limit the services to some services? like docker_services(excluding_services: List)

When in a development setting, this would be useful as we normally want to test the service with hot-reload functionality.

I checked fixture-parameterize, but that is intended for running against all the parameters provided 1 by 1.

@adityaguru149
Copy link
Author

I was reading the docs on fixtures and found that there is a way.

@pytest.mark.docker_services_required(["postgres", "redis"])
def test_app_up(docker_services):

I can try to raise a PR for this.
@AndreLouisCaron @Luminaar Any guidance with this?
Thanks in Advance.

@Luminaar
Copy link
Collaborator

Hello! Thanks for submitting the issue.
Could you please elaborate, what use-case do you have for this functionality? It's not completely clear to me.
My assumption is, that users need all services specified in docker-compose.yml for tests. If you need more than one combination of services, a workaround, for now, is having multiple .yml files and overriding the docker_compose_file fixture with parametrization.

@adityaguru149
Copy link
Author

adityaguru149 commented Sep 22, 2020

Hello @Luminaar

The idea that you are suggesting about keeping multiple docker-compose files would require me keep the files updated which I would like to avoid but presently I am doing that.

Let me try to explain the use-case again.
Use Case: I would like to start only some services/ or start all services except some while developing.
One of the most trivial forms of the use-case (that is easier to relate to) is run all services in docker-compose but exclude the service being tested.

Imagine a local development setting, I write few tests, write some code to make it pass, then refactor and repeat
If I face test failures I have to update code and test again.
It would be easier to update the code if it were running in local terminal not in some container.

Advantages:

  1. I run the service in my local terminal with debugging enabled
  2. I can have hot reload functionality on the service running on my terminal
  3. I use one docker-compose file and in test just have the flexibility to choose which services to start (and not worry about updating multiple docker-compose files)

Links discussing similar use cases:

  1. Docker compose issue
  2. Stackoverflow Q

If it is still unclear, can you help me with what exactly is unclear? I can try to remedy that

If you are clear on the use case, would you be able to review my suggestion?
I would like to know if there is a better way to do this

Thanks

@Luminaar
Copy link
Collaborator

I think I understand. Would a new fixture that would allow specifying a custom docker-compose up command help?

Right now, docker-compose up --build -d is run.

A new fixture (called docker_setup) would allow overriding that. Then you could specify which services are to be run in the command (as per the SO question)

@adityaguru149
Copy link
Author

I think I understand. Would a new fixture that would allow specifying a custom docker-compose up command help?

Right now, docker-compose up --build -d is run.

A new fixture (called docker_setup) would allow overriding that. Then you could specify which services are to be run in the command (as per the SO question)

Do we require a new fixture?

Can we go with pytest markers?
AFAIK this would allow us to use the docker_services fixture and parameterize it using a pytest marker, so that any test case or module that requires to configure can specify in the marker.

@pytest.mark.docker_services_required(["postgres", "redis"])
def test_app_up(docker_services):

@danihodovic
Copy link

Can we go with pytest markers?
AFAIK this would allow us to use the docker_services fixture and parameterize it using a pytest marker, so that any test case or module that requires to configure can specify in the marker.

👍 👍 👍

@Luminaar
Copy link
Collaborator

Luminaar commented Apr 9, 2022

Version 0.12.0 adds a way to customize docker-compose setup.

@Luminaar Luminaar closed this as completed Apr 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants