kaizendorks / pymongo_inmemory

A mongo mocking library with an ephemeral MongoDB running in memory.
MIT License
39 stars 13 forks source link

Fix issue #98 - Crash when using the mongod_port parameter #105

Closed ercaronte closed 4 months ago

ercaronte commented 4 months ago

This PR fixes issue https://github.com/kaizendorks/pymongo_inmemory/issues/98 When when using the mongod_port parameter the library code crashes with the following exception:

  File "/.../lib/python3.12/site-packages/pymongo_inmemory/mongod.py", line 143, in start
    self._proc = subprocess.Popen(boot_command)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/.../lib/python3.12/subprocess.py", line 1026, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/.../lib/python3.12/subprocess.py", line 1883, in _execute_child
    self.pid = _fork_exec(
               ^^^^^^^^^^^
TypeError: expected str, bytes or os.PathLike object, not int

The cause of the error is that the subprocess.Popen method does not accept int arguments, while the mongod_port parameter is forced as integer.

The mongod port value is set as str in all cases, except when passed as a customer parameter. The proposed code change fixes this case.

ercaronte commented 4 months ago

@ekarademir or @david-molnar-oculai can you please have a look at this PR?

david-molnar-oculai commented 4 months ago

Nice, I think I also run into this problem before. It's just annoying. Thanks for the fix.

dgk675 commented 4 months ago

Thanks, this solved my issue! A temporary workaround is to configure the Port as a str in setup.cfg

ekarademir commented 4 months ago

This is now published. Thank you for the contribution @SparksFlyx3