diff --git a/pytest.ini b/pytest.ini new file mode 100644 index 0000000000..daf6168964 --- /dev/null +++ b/pytest.ini @@ -0,0 +1,4 @@ +[pytest] +testpaths = + test +norecursedirs = test/* diff --git a/test/conftest.py b/test/conftest.py new file mode 100644 index 0000000000..400fd9ed75 --- /dev/null +++ b/test/conftest.py @@ -0,0 +1,10 @@ +from test import setup, teardown + +import pytest + + +@pytest.fixture(scope="session", autouse=True) +def test_setup_and_teardown(): + setup() + yield + teardown() diff --git a/test/test_cmap.py b/test/test_cmap.py index 3b84524f44..1676ed66da 100644 --- a/test/test_cmap.py +++ b/test/test_cmap.py @@ -24,7 +24,7 @@ from test.pymongo_mocks import DummyMonitor from test.utils import ( CMAPListener, - TestCreator, + SpecTestCreator, camel_to_snake, client_context, get_pool, @@ -455,7 +455,7 @@ def run_scenario(self): return run_scenario -class CMAPTestCreator(TestCreator): +class CMAPSpecTestCreator(SpecTestCreator): def tests(self, scenario_def): """Extract the tests from a spec file. @@ -465,7 +465,7 @@ def tests(self, scenario_def): return [scenario_def] -test_creator = CMAPTestCreator(create_test, TestCMAP, TestCMAP.TEST_PATH) +test_creator = CMAPSpecTestCreator(create_test, TestCMAP, TestCMAP.TEST_PATH) test_creator.create_tests() diff --git a/test/test_crud_v1.py b/test/test_crud_v1.py index 589da0a7d7..46aab2fba1 100644 --- a/test/test_crud_v1.py +++ b/test/test_crud_v1.py @@ -21,7 +21,7 @@ from test import IntegrationTest, unittest from test.utils import ( - TestCreator, + SpecTestCreator, camel_to_snake, camel_to_snake_args, camel_to_upper_camel, @@ -171,7 +171,7 @@ def run_scenario(self): return run_scenario -test_creator = TestCreator(create_test, TestAllScenarios, _TEST_PATH) +test_creator = SpecTestCreator(create_test, TestAllScenarios, _TEST_PATH) test_creator.create_tests() diff --git a/test/test_data_lake.py b/test/test_data_lake.py index ce210010bd..868cbe836b 100644 --- a/test/test_data_lake.py +++ b/test/test_data_lake.py @@ -23,7 +23,7 @@ from test.crud_v2_format import TestCrudV2 from test.utils import ( OvertCommandListener, - TestCreator, + SpecTestCreator, rs_client_noauth, rs_or_single_client, ) @@ -115,7 +115,7 @@ def run_scenario(self): return run_scenario -TestCreator(create_test, DataLakeTestSpec, _TEST_PATH).create_tests() +SpecTestCreator(create_test, DataLakeTestSpec, _TEST_PATH).create_tests() if __name__ == "__main__": diff --git a/test/test_encryption.py b/test/test_encryption.py index 0b9087359e..2f61b52ffb 100644 --- a/test/test_encryption.py +++ b/test/test_encryption.py @@ -50,7 +50,7 @@ from test.utils import ( AllowListEventListener, OvertCommandListener, - TestCreator, + SpecTestCreator, TopologyEventListener, camel_to_snake_args, is_greenthread_patched, @@ -695,7 +695,7 @@ def run_scenario(self): return run_scenario -test_creator = TestCreator(create_test, TestSpec, os.path.join(SPEC_PATH, "legacy")) +test_creator = SpecTestCreator(create_test, TestSpec, os.path.join(SPEC_PATH, "legacy")) test_creator.create_tests() diff --git a/test/test_read_write_concern_spec.py b/test/test_read_write_concern_spec.py index 2b39f7d04e..b27e9fa033 100644 --- a/test/test_read_write_concern_spec.py +++ b/test/test_read_write_concern_spec.py @@ -24,7 +24,7 @@ from test import IntegrationTest, client_context, unittest from test.utils import ( EventListener, - TestCreator, + SpecTestCreator, disable_replication, enable_replication, rs_or_single_client, @@ -337,7 +337,7 @@ def run_scenario(self): return run_scenario -test_creator = TestCreator(create_operation_test, TestOperation, TestOperation.TEST_PATH) +test_creator = SpecTestCreator(create_operation_test, TestOperation, TestOperation.TEST_PATH) test_creator.create_tests() diff --git a/test/test_retryable_reads.py b/test/test_retryable_reads.py index 97c51cd44f..df173ac27b 100644 --- a/test/test_retryable_reads.py +++ b/test/test_retryable_reads.py @@ -31,7 +31,7 @@ from test.utils import ( CMAPListener, OvertCommandListener, - TestCreator, + SpecTestCreator, rs_or_single_client, ) from test.utils_spec_runner import SpecRunner @@ -138,7 +138,7 @@ def run_scenario(self): return run_scenario -test_creator = TestCreator(create_test, TestSpec, _TEST_PATH) +test_creator = SpecTestCreator(create_test, TestSpec, _TEST_PATH) test_creator.create_tests() diff --git a/test/test_retryable_writes.py b/test/test_retryable_writes.py index 32841a8227..89507b33c3 100644 --- a/test/test_retryable_writes.py +++ b/test/test_retryable_writes.py @@ -28,7 +28,7 @@ DeprecationFilter, EventListener, OvertCommandListener, - TestCreator, + SpecTestCreator, rs_or_single_client, ) from test.utils_spec_runner import SpecRunner @@ -120,7 +120,7 @@ def run_scenario(self): return run_scenario -test_creator = TestCreator(create_test, TestAllScenarios, _TEST_PATH) +test_creator = SpecTestCreator(create_test, TestAllScenarios, _TEST_PATH) test_creator.create_tests() diff --git a/test/test_server_selection_in_window.py b/test/test_server_selection_in_window.py index 63769a6457..6c015e0ed2 100644 --- a/test/test_server_selection_in_window.py +++ b/test/test_server_selection_in_window.py @@ -19,7 +19,7 @@ from test import IntegrationTest, client_context, unittest from test.utils import ( OvertCommandListener, - TestCreator, + SpecTestCreator, get_pool, rs_client, wait_until, @@ -76,7 +76,7 @@ def run_scenario(self): return run_scenario -class CustomTestCreator(TestCreator): +class CustomSpecTestCreator(SpecTestCreator): def tests(self, scenario_def): """Extract the tests from a spec file. @@ -86,7 +86,7 @@ def tests(self, scenario_def): return [scenario_def] -CustomTestCreator(create_test, TestAllScenarios, TEST_PATH).create_tests() +CustomSpecTestCreator(create_test, TestAllScenarios, TEST_PATH).create_tests() class FinderThread(threading.Thread): diff --git a/test/test_transactions.py b/test/test_transactions.py index 9b51927d67..57495b0ab7 100644 --- a/test/test_transactions.py +++ b/test/test_transactions.py @@ -23,7 +23,7 @@ from test import client_context, unittest from test.utils import ( OvertCommandListener, - TestCreator, + SpecTestCreator, rs_client, single_client, wait_until, @@ -581,11 +581,11 @@ def run_scenario(self): return run_scenario -test_creator = TestCreator(create_test, TestTransactions, TEST_PATH) +test_creator = SpecTestCreator(create_test, TestTransactions, TEST_PATH) test_creator.create_tests() -TestCreator( +SpecTestCreator( create_test, TestTransactionsConvenientAPI, TestTransactionsConvenientAPI.TEST_PATH ).create_tests() diff --git a/test/utils.py b/test/utils.py index 810a02b872..86edae8808 100644 --- a/test/utils.py +++ b/test/utils.py @@ -391,7 +391,7 @@ def call_count(self): return len(self._call_list) -class TestCreator: +class SpecTestCreator: """Class to create test cases from specifications.""" def __init__(self, create_test, test_class, test_path): diff --git a/tox.ini b/tox.ini index 46c1a697de..f6e2f1f755 100644 --- a/tox.ini +++ b/tox.ini @@ -4,6 +4,8 @@ requires = envlist = # Test using the system Python. test, + # Test the extra encryption functionality. + test-encryption, # Run pre-commit on all files. lint, # Run pre-commit on all files, including stages that require manual fixes. @@ -24,10 +26,21 @@ envlist = linkcheck [testenv:test] -description = run unit tests +description = run base set of unit tests with no extra functionality +deps = + pytest>=7 commands = python --version - python setup.py test {posargs} + pytest -v -rs {posargs} + +[testenv:test-encryption] +description = run base unit tests with encryption enabled +deps = {[testenv:test]deps} +extras = encryption +commands = + python --version + pytest {posargs} + [testenv:lint] description = run pre-commit @@ -45,25 +58,24 @@ commands = [testenv:typecheck-mypy] description = run mypy and pyright to typecheck +extras = + encryption + ocsp + zstd + aws deps = - mypy - zstandard + mypy==1.2.0 certifi; platform_system == "win32" or platform_system == "Darwin" typing_extensions - pyopenssl>=17.2.0 - requests<3.0.0 - service_identity>=18.1.0 - pymongocrypt>=1.6.0,<2.0.0 - pymongo-auth-aws<2.0.0 commands = mypy --install-types --non-interactive bson gridfs tools pymongo - mypy --install-types --non-interactive --disable-error-code var-annotated --disable-error-code attr-defined --disable-error-code union-attr --disable-error-code assignment --disable-error-code no-redef --disable-error-code index --allow-redefinition --allow-untyped-globals --exclude "test/mypy_fails/*.*" test + mypy --install-types --non-interactive --disable-error-code var-annotated --disable-error-code attr-defined --disable-error-code union-attr --disable-error-code assignment --disable-error-code no-redef --disable-error-code index --allow-redefinition --allow-untyped-globals --exclude "test/mypy_fails/*.*" --exclude "test/conftest.py" test mypy --install-types --non-interactive test/test_typing.py test/test_typing_strict.py [testenv:typecheck-pyright] description = run pyright to typecheck deps = - mypy + mypy==1.2.0 pyright==1.1.290 commands = pyright test/test_typing.py test/test_typing_strict.py