From d49427f7146fa365f83e0e8051f91821b74e96b9 Mon Sep 17 00:00:00 2001 From: Noah Stapp Date: Thu, 15 Jun 2023 11:54:50 -0700 Subject: [PATCH 01/14] PYTHON-3738 Use tox for sphinx doc instead of setup.py --- tox.ini | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tox.ini b/tox.ini index e199914cb5..3aa5ffa20c 100644 --- a/tox.ini +++ b/tox.ini @@ -75,3 +75,17 @@ commands = {[testenv:typecheck-mypy]commands} {[testenv:typecheck-pyright]commands} {[testenv:typecheck-pyright-strict]commands} + +[testenv:doc-test] +description = run sphinx doc tests +deps = + sphinx +commands = + sphinx-build -E -b doctest doc ./doc/_build/doctest + +[testenv:doc] +description = build sphinx docs +deps = + sphinx +commands = + pre-commit run --all-files --hook-stage manual From 852aaf297a3d512a433e19a01a41be19795dcb3f Mon Sep 17 00:00:00 2001 From: Noah Stapp Date: Thu, 15 Jun 2023 17:41:58 -0700 Subject: [PATCH 02/14] Add linkcheck command to tox --- .github/workflows/test-python.yml | 7 ++----- tox.ini | 17 ++++++++++++----- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/.github/workflows/test-python.yml b/.github/workflows/test-python.yml index 83def93f57..6dbb7cb558 100644 --- a/.github/workflows/test-python.yml +++ b/.github/workflows/test-python.yml @@ -80,12 +80,9 @@ jobs: - uses: actions/setup-python@v2 with: cache: 'pip' - cache-dependency-path: 'setup.py' - name: Install dependencies run: | - python -m pip install -U pip - python -m pip install sphinx + pip install tox - name: Check links run: | - cd doc - make linkcheck + tox -e linkcheck diff --git a/tox.ini b/tox.ini index 3aa5ffa20c..2d21d8938f 100644 --- a/tox.ini +++ b/tox.ini @@ -76,16 +76,23 @@ commands = {[testenv:typecheck-pyright]commands} {[testenv:typecheck-pyright-strict]commands} +[testenv:doc] +description = build sphinx docs +deps = + sphinx +commands = + sphinx-build -E -b doc doc ./doc/_build/html + [testenv:doc-test] description = run sphinx doc tests deps = - sphinx + {[testenv:doc]deps} commands = sphinx-build -E -b doctest doc ./doc/_build/doctest -[testenv:doc] -description = build sphinx docs +[testenv:linkcheck] +description = check links of sphinx docs deps = - sphinx + {[testenv:doc]deps} commands = - pre-commit run --all-files --hook-stage manual + sphinx-build -E -b linkcheck doc ./doc/_build/linkcheck From 132caf06f5c58d67f3e1c4e70da3c1f7a4cd779f Mon Sep 17 00:00:00 2001 From: Noah Stapp Date: Fri, 16 Jun 2023 13:32:58 -0700 Subject: [PATCH 03/14] Update tox envs --- tox.ini | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/tox.ini b/tox.ini index 2d21d8938f..6e9f73cd64 100644 --- a/tox.ini +++ b/tox.ini @@ -8,8 +8,20 @@ envlist = lint, # Run pre-commit on all files, including stages that require manual fixes. lint-manual, + # Typecheck using mypy. + typecheck-mypy, + # Typecheck using pyright. + typecheck-pyright, + # Typecheck using pyright strict. + typecheck-pyright-strict, # Typecheck all files. - typecheck + typecheck, + # Build sphinx docs + doc, + # Test sphinx docs + doc-test, + # Linkcheck sphin docs + linkcheck [testenv:test] description = run unit tests From 0ed29fa3b17154ee96d7213bfb37afa48a9b1836 Mon Sep 17 00:00:00 2001 From: Noah Stapp Date: Fri, 16 Jun 2023 13:42:08 -0700 Subject: [PATCH 04/14] Fix tox doc env --- tox.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tox.ini b/tox.ini index 6e9f73cd64..9afa1923c9 100644 --- a/tox.ini +++ b/tox.ini @@ -93,7 +93,7 @@ description = build sphinx docs deps = sphinx commands = - sphinx-build -E -b doc doc ./doc/_build/html + sphinx-build -E -b html doc ./doc/_build/html [testenv:doc-test] description = run sphinx doc tests From a58ecc8d6b14270fba8aaa8359ed2a47e39d4f44 Mon Sep 17 00:00:00 2001 From: Noah Stapp Date: Fri, 16 Jun 2023 13:44:48 -0700 Subject: [PATCH 05/14] Fix linkcheck action dependency path --- .github/workflows/test-python.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test-python.yml b/.github/workflows/test-python.yml index 6dbb7cb558..d7c442cc49 100644 --- a/.github/workflows/test-python.yml +++ b/.github/workflows/test-python.yml @@ -80,6 +80,7 @@ jobs: - uses: actions/setup-python@v2 with: cache: 'pip' + cache-dependency-path: 'setup.py' - name: Install dependencies run: | pip install tox From c667dfba9fddd6065495a4312448856c11578fa9 Mon Sep 17 00:00:00 2001 From: Noah Stapp Date: Fri, 16 Jun 2023 09:11:58 -0700 Subject: [PATCH 06/14] PYTHON-3727 Use tox for unit tests and switch to pytest --- pytest.ini | 4 ++++ test/test_cmap.py | 6 +++--- test/test_crud_v1.py | 4 ++-- test/test_data_lake.py | 4 ++-- test/test_encryption.py | 4 ++-- test/test_read_write_concern_spec.py | 4 ++-- test/test_retryable_reads.py | 4 ++-- test/test_retryable_writes.py | 4 ++-- test/test_server_selection_in_window.py | 6 +++--- test/test_transactions.py | 6 +++--- test/utils.py | 2 +- tox.ini | 15 +++++++++++++-- 12 files changed, 39 insertions(+), 24 deletions(-) create mode 100644 pytest.ini 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/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 9afa1923c9..0573a9cf34 100644 --- a/tox.ini +++ b/tox.ini @@ -25,9 +25,20 @@ envlist = [testenv:test] description = run unit tests +deps = + pytest>=7 + mockupdb + mypy + zstandard + 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 = - python --version - python setup.py test {posargs} + pytest {posargs} [testenv:lint] description = run pre-commit From f616c1e4247e4415b1348fbbe0f24c92c00ac09b Mon Sep 17 00:00:00 2001 From: Noah Stapp Date: Tue, 20 Jun 2023 15:00:20 -0700 Subject: [PATCH 07/14] Remove all extra dependencies for default tox test --- .github/workflows/test-python.yml | 1 - tox.ini | 22 +++++++++++++--------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/.github/workflows/test-python.yml b/.github/workflows/test-python.yml index d7c442cc49..a24ad9a12c 100644 --- a/.github/workflows/test-python.yml +++ b/.github/workflows/test-python.yml @@ -32,7 +32,6 @@ jobs: with: python-version: ${{ matrix.python-version }} cache: 'pip' - cache-dependency-path: 'setup.py' - name: Install dependencies run: | pip install tox diff --git a/tox.ini b/tox.ini index 0573a9cf34..5ebfb481b9 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,22 +26,24 @@ envlist = linkcheck [testenv:test] -description = run unit tests +description = run base set of unit tests with no extra functionality deps = pytest>=7 - mockupdb - mypy - zstandard - certifi; platform_system == "win32" or platform_system == "Darwin" - typing_extensions - pyopenssl>=17.2.0 - requests<3.0.0 - service_identity>=18.1.0 +commands = + python --version + pytest {posargs} + +[testenv:test-encryption] +description = run base unit tests with encryption enabled +deps = + {[testenv:test]deps} pymongocrypt>=1.6.0,<2.0.0 pymongo-auth-aws<2.0.0 commands = + python --version pytest {posargs} + [testenv:lint] description = run pre-commit deps = From 74c66c8fb9d82b4afed0bde2867dafdb0654ad4b Mon Sep 17 00:00:00 2001 From: Noah Stapp Date: Tue, 20 Jun 2023 15:32:32 -0700 Subject: [PATCH 08/14] Use setup.py for cache dependency --- .github/workflows/test-python.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test-python.yml b/.github/workflows/test-python.yml index a24ad9a12c..d7c442cc49 100644 --- a/.github/workflows/test-python.yml +++ b/.github/workflows/test-python.yml @@ -32,6 +32,7 @@ jobs: with: python-version: ${{ matrix.python-version }} cache: 'pip' + cache-dependency-path: 'setup.py' - name: Install dependencies run: | pip install tox From 7290043c64cb00b71a509f0738d18f4025271b37 Mon Sep 17 00:00:00 2001 From: Noah Stapp Date: Wed, 21 Jun 2023 10:33:39 -0700 Subject: [PATCH 09/14] Add session-wide fixture for test setup and teardown --- test/conftest.py | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 test/conftest.py 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() From 829d1cf675e0db3fad677a2b1af2474a5551b923 Mon Sep 17 00:00:00 2001 From: Noah Stapp Date: Wed, 21 Jun 2023 10:38:24 -0700 Subject: [PATCH 10/14] Exclude test/conftest.py from typechecking --- tox.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tox.ini b/tox.ini index 7c3a7d36d1..2672c3a09c 100644 --- a/tox.ini +++ b/tox.ini @@ -72,7 +72,7 @@ deps = 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] From a7ae48fbe525da90e9244ae4f208d464f1f10ee7 Mon Sep 17 00:00:00 2001 From: Noah Stapp Date: Wed, 21 Jun 2023 11:31:03 -0700 Subject: [PATCH 11/14] Turn on verbose pytest --- tox.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tox.ini b/tox.ini index 2672c3a09c..13817e4c30 100644 --- a/tox.ini +++ b/tox.ini @@ -31,7 +31,7 @@ deps = pytest>=7 commands = python --version - pytest {posargs} + pytest -v {posargs} [testenv:test-encryption] description = run base unit tests with encryption enabled From 03197a2febcd392d7ad45a349abbdb1455ce1e5c Mon Sep 17 00:00:00 2001 From: Noah Stapp Date: Wed, 21 Jun 2023 11:38:27 -0700 Subject: [PATCH 12/14] Add skip summary to tox test --- tox.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tox.ini b/tox.ini index 13817e4c30..6ce8fe0f96 100644 --- a/tox.ini +++ b/tox.ini @@ -31,7 +31,7 @@ deps = pytest>=7 commands = python --version - pytest -v {posargs} + pytest -v -rs {posargs} [testenv:test-encryption] description = run base unit tests with encryption enabled From 750e6ac2fc73c1df670216982809637eaf884fef Mon Sep 17 00:00:00 2001 From: Noah Stapp Date: Wed, 21 Jun 2023 12:27:05 -0700 Subject: [PATCH 13/14] PYTHON-3756 Pin mypy version used in test suite to 1.2.0 --- tox.ini | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tox.ini b/tox.ini index 6ce8fe0f96..9fd1f65afa 100644 --- a/tox.ini +++ b/tox.ini @@ -61,7 +61,7 @@ commands = [testenv:typecheck-mypy] description = run mypy and pyright to typecheck deps = - mypy + mypy==1.2.0 zstandard certifi; platform_system == "win32" or platform_system == "Darwin" typing_extensions @@ -78,7 +78,7 @@ commands = [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 From af819c84b51b37fbc900c9f5d10c8abb2a8b54d8 Mon Sep 17 00:00:00 2001 From: Noah Stapp Date: Wed, 21 Jun 2023 14:36:01 -0700 Subject: [PATCH 14/14] Use extras in tox --- tox.ini | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/tox.ini b/tox.ini index 9fd1f65afa..f6e2f1f755 100644 --- a/tox.ini +++ b/tox.ini @@ -35,10 +35,8 @@ commands = [testenv:test-encryption] description = run base unit tests with encryption enabled -deps = - {[testenv:test]deps} - pymongocrypt>=1.6.0,<2.0.0 - pymongo-auth-aws<2.0.0 +deps = {[testenv:test]deps} +extras = encryption commands = python --version pytest {posargs} @@ -60,16 +58,15 @@ commands = [testenv:typecheck-mypy] description = run mypy and pyright to typecheck +extras = + encryption + ocsp + zstd + aws deps = mypy==1.2.0 - zstandard 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/*.*" --exclude "test/conftest.py" test