testcontainers-python icon indicating copy to clipboard operation
testcontainers-python copied to clipboard

Add CustomContainer exposing settings through the class

Open vikahl opened this issue 3 years ago • 10 comments

Add a CustomContainer exposing the settings through the class.

Close #236

vikahl avatar Aug 25 '22 13:08 vikahl

Great, thank you! Slight misunderstanding: I was thinking that we could add this functionality to existing containers rather than create a new one. What do you think?

tillahoffmann avatar Aug 25 '22 14:08 tillahoffmann

Great, thank you! Slight misunderstanding: I was thinking that we could add this functionality to existing containers rather than create a new one. What do you think?

I don't there is any current class (except for the deprecated TestContainer, but probably best to not touch it) that allows specifying the image name. I build the service image prior to tests so I have e.g., my-service:version1 as an image and want to manually specify that.

vikahl avatar Aug 25 '22 15:08 vikahl

The image name can be specified for DockerContainer here.

https://github.com/testcontainers/testcontainers-python/blob/7346345d3636c383e6a685fc80b67c5947efd9fe/testcontainers/core/container.py#L12-L13

tillahoffmann avatar Aug 25 '22 17:08 tillahoffmann

The image name can be specified for DockerContainer here.

https://github.com/testcontainers/testcontainers-python/blob/7346345d3636c383e6a685fc80b67c5947efd9fe/testcontainers/core/container.py#L12-L13

True, you have a point there.

Just to clarify, do you suggest extending the __init__ method of DockerContainer or all the db-containers?

I think the DockerContainer approach would be convenient and won't require a new class. I can test the approach tomorrow and see if it would impact existing implementations.

vikahl avatar Aug 25 '22 19:08 vikahl

Just to clarify, do you suggest extending the init method of DockerContainer or all the db-containers?

I was thinking all the containers as they all inherit from DockerContainer. That would give us a consistent interface across the whole library.

tillahoffmann avatar Aug 30 '22 14:08 tillahoffmann

Just to clarify, do you suggest extending the init method of DockerContainer or all the db-containers?

I was thinking all the containers as they all inherit from DockerContainer. That would give us a consistent interface across the whole library.

Ah, good thought. Sorry for not picking up on this but I'll update the PR.

vikahl avatar Mar 16 '23 08:03 vikahl

@tillahoffmann updated the PR to instead set these in the core container's __init__. Do you think this looks reasonable?

If so, I'll make sure these changes are covered by tests as well.

vikahl avatar Mar 22 '23 19:03 vikahl

Ping @tillahoffmann this is another great PR

gaby avatar Jun 08 '23 04:06 gaby

Will take a look and add tests and do the updates when I am back at a computer (might take a few weeks)

vikahl avatar Jun 09 '23 14:06 vikahl

@tillahoffmann please take a look at the tests.

I added test that tests that attributes can be set through the init function and later read through class attr.

The test does not test that the attributes has an actual effect, in the future it might be of interest to test the integration to the docker container and ensure that class attributes are propagated properly. However, I for the changes in this PR I think the current is good enough.

vikahl avatar Jun 27 '23 17:06 vikahl