It turns out that many server releases ago MongoDB stopped including process id when generating ObjectIds and instead started generating 5 random bytes for machine id + process id. That makes part of this test useless. The reason the test fails (very infrequently) is that we sometimes get (un)lucky and the 2 byte process id from pymongo matches the 2 randomly generated bytes from the server.
[2017/03/28 00:20:34.124] ====================================================================== [2017/03/28 00:20:34.124] FAIL: test_insert_manipulate_false (test_legacy_api.TestLegacy) [2017/03/28 00:20:34.124] ---------------------------------------------------------------------- [2017/03/28 00:20:34.124] Traceback (most recent call last): [2017/03/28 00:20:34.124] File "/data/mci/7ec89c95ebff9335654af04ed126122b/src/test/test_legacy_api.py", line 267, in test_insert_manipulate_false [2017/03/28 00:20:34.124] self.assertFalse(oid_generated_on_client(server_doc['_id'])) [2017/03/28 00:20:34.124] AssertionError: True is not false