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

Optionally allow running tests with mongomock #1081

Closed
jelly opened this issue Jun 30, 2024 · 3 comments
Closed

Optionally allow running tests with mongomock #1081

jelly opened this issue Jun 30, 2024 · 3 comments

Comments

@jelly
Copy link

jelly commented Jun 30, 2024

The problem

factory-boy is packaged in Arch Linux and tests run while building the package in this buildchroot. The mongodb tests require a running mongodb server, mongodb is neither packaged nor is it possible to run a service during building.

Proposed solution

I've patched factory-boy to use mongomock, this succesfully ran the tests. Maybe factory-boy can optionally allow running the tests with mongomock when available.

@@ -10,6 +10,8 @@
 except ImportError:
     raise unittest.SkipTest("mongodb tests disabled.")

+import mongomock
+
 import factory
 from factory.mongoengine import MongoEngineFactory

@@ -57,6 +59,7 @@
             # PyMongo>=2.1 has a 20s timeout, use 100ms instead
             serverselectiontimeoutms=cls.server_timeout_ms,
             uuidRepresentation='standard',
+            mongo_client_class=mongomock.MongoClient,
         )

     @classmethod
@francoisfreitag
Copy link
Member

francoisfreitag commented Jul 2, 2024

I see that these tests should be skipped when mongoengine is not available. Why not skip the tests since mongodb is not available?

@jelly
Copy link
Author

jelly commented Jul 2, 2024

That is also an option, but it is still nice to run the tests. In theory users can run a mongodb server via podman and we do provide mongoengine in the repositories.

@francoisfreitag
Copy link
Member

I have opened a pull request to support that use case, please feel free to try out the patch and let us know if that would work for you!

rbarrois added a commit that referenced this issue Aug 18, 2024
rbarrois added a commit that referenced this issue Aug 18, 2024
rbarrois added a commit that referenced this issue Aug 18, 2024
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

Successfully merging a pull request may close this issue.

2 participants