Testcontainers is a Python library that providing a friendly API to run Docker container. It is designed to create runtime environment to use during your automatic tests.
mongomock can often be used in unit testing of mongodb-related functionality. It's faster and easier than using docker containers for such tests. But perhaps one of the most important scenarios in which mongomock is not applicable is testing the functionality using MongoDB transactions. At the moment, transaction mocking is not implemented in mongomock. But even if support for this was implemented there, such sensitive functionality (using transactions) would like to be checked "naturally". But as you know, transactions are possible only for replica sets, which the default MongoDB container is not. It is possible to configure mongodb as a replicaset (although with one node, but I think this is not critical for testing).
If you find this functionality useful here in the public, I can provide a PR (either as a separate Mongodb container, or extend the current MongoDbContainer with configuration options). What do you think about it?
What are you trying to do?
Unit testing of Mongodb transactions.
Why should it be done this way?
mongomock can often be used in unit testing of mongodb-related functionality. It's faster and easier than using docker containers for such tests. But perhaps one of the most important scenarios in which
mongomock
is not applicable is testing the functionality using MongoDB transactions. At the moment, transaction mocking is not implemented inmongomock
. But even if support for this was implemented there, such sensitive functionality (using transactions) would like to be checked "naturally". But as you know, transactions are possible only for replica sets, which the default MongoDB container is not. It is possible to configure mongodb as a replicaset (although with one node, but I think this is not critical for testing).If you find this functionality useful here in the public, I can provide a PR (either as a separate Mongodb container, or extend the current
MongoDbContainer
with configuration options). What do you think about it?