Reduce scattered insert_one({}) collection-priming calls in test suite

XMLWordPrintableJSON

    • Type: Task
    • Resolution: Unresolved
    • Priority: Unknown
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • None
    • Python Drivers
    • None
    • None
    • None
    • None
    • None
    • None

      Context

      Many tests insert an empty document (`insert_one({})`) to force a collection into existence before exercising operations that require a pre-existing collection (e.g. index listing, rename, change streams, cursor behaviour). This pattern is scattered ad-hoc across 24 test files rather than consolidated in a shared setup.

      A codebase-wide audit found 183 occurrences of insert_one({}) used purely as a collection-priming step (none in setUpClass; 2 in setUp/asyncSetUp).

      file Sync Async
      test_session.py 11 11
      test_transactions.py 10 10
      test_change_stream.py 9 9
      test_index_management.py 7 7
      test_client.py 7 7
      test_retryable_writes.py 6 6
      test_collection.py 5 5
      test_sdam_monitoring_spec.py 4 4
      test_auth_oidc.py 4 4
      test_read_write_concern_spec.py 4 4
      test_pooling.py 4 4
      test_database.py 4 4
      test_cursor.py 3 2
      test_max_staleness.py 2 2
      test_csot.py 2 2
      test_connections_survive_primary_stepdown_spec.py 2 2
      test_typing.py 2
      mockupdb/test_op_msg.py 2
      Others (monitoring, encryption, discovery, read_prefs, examples, custom_types) 6 5
      TOTAL 93 90

      Definition of done

      Evaluate and consolidate the priming pattern:

      • Move to setUp/asyncSetUp on relevant base classes where the whole test class needs a pre-existing collection
      • Replace with explicit create_collection() calls where the intent is to test against an existing collection specifically. This improves readability and stops tribal knowledge.

      Pitfalls

      Some tests may need collection creation to occur midway through to generate errors.

            Assignee:
            Unassigned
            Reporter:
            Jib Adegunloye
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: