diff --git a/test/test_create_entities.py b/test/test_create_entities.py index ad0ac9347e..1e46614da0 100644 --- a/test/test_create_entities.py +++ b/test/test_create_entities.py @@ -11,11 +11,16 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +import sys import unittest + +sys.path[0:0] = [""] + +from test import IntegrationTest from test.unified_format import UnifiedSpecTestMixinV1 -class TestCreateEntities(unittest.TestCase): +class TestCreateEntities(IntegrationTest): def test_store_events_as_entities(self): self.scenario_runner = UnifiedSpecTestMixinV1() spec = { @@ -91,7 +96,7 @@ def test_store_all_others_as_entities(self): { "name": "insertOne", "object": "collection0", - "arguments": {"document": {"_id": 1, "x": 44}}, + "arguments": {"document": {"_id": 2, "x": 44}}, }, ], }, @@ -101,15 +106,19 @@ def test_store_all_others_as_entities(self): ], } + self.client.dat.dat.delete_many({}) self.scenario_runner.TEST_SPEC = spec self.scenario_runner.setUp() self.scenario_runner.run_scenario(spec["tests"][0]) self.scenario_runner.entity_map["client0"].close() - final_entity_map = self.scenario_runner.entity_map - for entity in ["errors", "failures"]: - self.assertIn(entity, final_entity_map) - self.assertGreaterEqual(len(final_entity_map[entity]), 0) - self.assertEqual(type(final_entity_map[entity]), list) - for entity in ["successes", "iterations"]: - self.assertIn(entity, final_entity_map) - self.assertEqual(type(final_entity_map[entity]), int) + entity_map = self.scenario_runner.entity_map + self.assertEqual(len(entity_map["errors"]), 4) + for error in entity_map["errors"]: + self.assertEqual(error["type"], "DuplicateKeyError") + self.assertEqual(entity_map["failures"], []) + self.assertEqual(entity_map["successes"], 2) + self.assertEqual(entity_map["iterations"], 5) + + +if __name__ == "__main__": + unittest.main() diff --git a/test/test_mypy.py b/test/test_mypy.py index 58e69853ca..3b29bbf20e 100644 --- a/test/test_mypy.py +++ b/test/test_mypy.py @@ -15,6 +15,7 @@ """Test that each file in mypy_fails/ actually fails mypy, and test some sample client code that uses PyMongo typings.""" import os +import sys import tempfile import unittest from typing import TYPE_CHECKING, Any, Dict, Iterable, Iterator, List, Union @@ -51,7 +52,9 @@ class ImplicitMovie(TypedDict): except ImportError: api = None # type: ignore[assignment] -from test import IntegrationTest +sys.path[0:0] = [""] + +from test import IntegrationTest, client_context from test.utils import rs_or_single_client from bson import CodecOptions, decode, decode_all, decode_file_iter, decode_iter, encode @@ -430,6 +433,7 @@ def test_typeddict_empty_document_type(self) -> None: # This should fail because _id is not included in our TypedDict definition. assert out["_id"] # type:ignore[typeddict-item] + @client_context.require_connection def test_typeddict_find_notrequired(self): if NotRequired is None or ImplicitMovie is None: raise unittest.SkipTest("Python 3.11+ is required to use NotRequired.")