Importing the "test" module automatically initializes a global ClientContext object, and the ClientContext constructor connects to the server and discovers its configuration, all while Python is holding the import lock. This makes the test module prone to deadlock, either in elaborate scenarios like Motor's synchrotest (MOTOR-226) or in more ordinary situations as we develop PyMongo and its test runner.
Let's do less work at import-time in the "test" module. Don't connect to the server in ClientContext's constructor; defer that until someone calls a new method named ClientContext.init(). We can make that method idempotent and call it from IntegrationTest.setUpClass() to ensure it's always run exactly once before tests start. Furthermore, even ClientContext.init() can do less work, its use of getCmdLineOpts to discover auth configuration is outdated.
- is depended on by
-
MOTOR-226 synchrotest hangs on Mac
- Closed