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

Is there a way to share the same single container instance between suites?

Open pgorin opened this issue 4 years ago • 3 comments

Hi, first of all, thank you for your work, I use it extensively :) I wll be glad if you can guide me with this issue!

Regards, Pato.

pgorin avatar Jan 21 '21 12:01 pgorin

Hi @pgorin. At the current moment, there is no supported way for doing this. It's because scalatest doesn't provide any functionality for sharing data like this between tests.

But there is a bit hacky way for sharing containers: you can start containers and just don't stop them. Testcontainers will eventually close all started containers after your tests. There is a special Ryuk container for that. Testcontainers always start it before any other container to avoid resource leaking.

LMnet avatar Jan 22 '21 02:01 LMnet

Hi Yuriy, thank you for your reply. What do you mean about a special Ryuk container? Can I still using TestContainerForAll approach or I have to perform custom before and after routines?

Again, thank you!

pgorin avatar Jan 26 '21 09:01 pgorin

https://hub.docker.com/r/testcontainers/ryuk

Can I still using TestContainerForAll approach or I have to perform custom before and after routines?

No, you can't use TestContainerForAll or any other built-in traits for that approach. You will need to manually start containers and don't stop them after tests. Also, you will need to somehow share containers between tests (through some global state).

LMnet avatar Jan 26 '21 09:01 LMnet