Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[pytest]
testpaths =
test
norecursedirs = test/*
10 changes: 10 additions & 0 deletions test/conftest.py
Original file line number Diff line number Diff line change
@@ -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()
6 changes: 3 additions & 3 deletions test/test_cmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from test.pymongo_mocks import DummyMonitor
from test.utils import (
CMAPListener,
TestCreator,
SpecTestCreator,
camel_to_snake,
client_context,
get_pool,
Expand Down Expand Up @@ -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.

Expand All @@ -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()


Expand Down
4 changes: 2 additions & 2 deletions test/test_crud_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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()


Expand Down
4 changes: 2 additions & 2 deletions test/test_data_lake.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down Expand Up @@ -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__":
Expand Down
4 changes: 2 additions & 2 deletions test/test_encryption.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
from test.utils import (
AllowListEventListener,
OvertCommandListener,
TestCreator,
SpecTestCreator,
TopologyEventListener,
camel_to_snake_args,
is_greenthread_patched,
Expand Down Expand Up @@ -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()


Expand Down
4 changes: 2 additions & 2 deletions test/test_read_write_concern_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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()


Expand Down
4 changes: 2 additions & 2 deletions test/test_retryable_reads.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
from test.utils import (
CMAPListener,
OvertCommandListener,
TestCreator,
SpecTestCreator,
rs_or_single_client,
)
from test.utils_spec_runner import SpecRunner
Expand Down Expand Up @@ -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()


Expand Down
4 changes: 2 additions & 2 deletions test/test_retryable_writes.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
DeprecationFilter,
EventListener,
OvertCommandListener,
TestCreator,
SpecTestCreator,
rs_or_single_client,
)
from test.utils_spec_runner import SpecRunner
Expand Down Expand Up @@ -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()


Expand Down
6 changes: 3 additions & 3 deletions test/test_server_selection_in_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from test import IntegrationTest, client_context, unittest
from test.utils import (
OvertCommandListener,
TestCreator,
SpecTestCreator,
get_pool,
rs_client,
wait_until,
Expand Down Expand Up @@ -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.

Expand All @@ -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):
Expand Down
6 changes: 3 additions & 3 deletions test/test_transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from test import client_context, unittest
from test.utils import (
OvertCommandListener,
TestCreator,
SpecTestCreator,
rs_client,
single_client,
wait_until,
Expand Down Expand Up @@ -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()

Expand Down
2 changes: 1 addition & 1 deletion test/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
34 changes: 23 additions & 11 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand All @@ -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
Expand Down