class_docstr: Call to methods wrapped with `mongodb_exception_wrapper()`.
class_docstr_tok: ["Call","to","methods","wrapped","with","`","mongodb_exception_wrapper","(",")","`","."]
docstr: Should raise generic DuplicateKeyError.
docstr_tok: ["Should","raise","generic","DuplicateKeyError","."]
code: def test_bulk_duplicate_key_error(
      self, monkeypatch, orion_db, test_collection
  ):
      """Should raise generic DuplicateKeyError."""
      # Make sure it raises pymongo.errors.BulkWriteError when there is no
      # wrapper
      monkeypatch.setattr(
          orion_db,
          "write",
          functools.partial(orion_db.write.__wrapped__, orion_db),
      )
      with pytest.raises(pymongo.errors.BulkWriteError) as exc_info:
          orion_db.write("test_collection", test_collection)
  
      monkeypatch.undo()
  
      # Verify that the wrapper converts it properly to DuplicateKeyError
      with pytest.raises(DuplicateKeyError) as exc_info:
          orion_db.write("test_collection", test_collection)
      assert "duplicate key error" in str(exc_info.value)
  
imports: import functools
  from timeit import timeit
  import pymongo
  import pytest
  from pymongo import MongoClient
  from orion.core.io.database import Database, DatabaseError, DuplicateKeyError
  from orion.core.io.database.mongodb import AUTH_FAILED_MESSAGES, MongoDB
  from .conftest import insert_test_collection
  from .test_database import get_db
label_desc: Use image node_id 2 for calling the TestExceptionWrapper obj's underlying member method code with example usage: obj.test_bulk_duplicate_key_error(monkeypatch, orion_db, test_collection) without return types