title: How to initialize MongoClient in a multiprocess Flask application?
body: <p>I have a Flask application which I'm running with uWSGI. The application initializes a <code>MongoClient()</code>. When running uWSGI with multiple workers I'm getting the <code>MongoClient opened before fork</code> warning.</p>
  <p>I saw that one way to overcome this problem is to initializethe MongoClient inside an init method decorated with uWSGI's <code>@postfork</code></p>
  <p>The problem is that after the change my tests fails because pytest can't find <code>uwsgi</code></p>
  <pre><code>#15 1.880 usr/local/lib/python3.9/site-packages/uwsgidecorators.py:10: in &lt;module&gt;
  #15 1.880     import uwsgi
  #15 1.880 E   ModuleNotFoundError: No module named 'uwsgi'
  </code></pre>
  <p><strong>Questions:</strong></p>
  <ul>
  <li>Is there any other easy way to initialize a <code>MongoClient</code> for each process?</li>
  <li>If not, how can I test my <code>app.py</code>?</li>
  </ul>