PYTHON-3727 Use tox for unit tests and switch to pytest (#1249)
This commit is contained in:
parent
bafb73cb8c
commit
b16e06acfd
4
pytest.ini
Normal file
4
pytest.ini
Normal file
@ -0,0 +1,4 @@
|
||||
[pytest]
|
||||
testpaths =
|
||||
test
|
||||
norecursedirs = test/*
|
||||
10
test/conftest.py
Normal file
10
test/conftest.py
Normal file
@ -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()
|
||||
@ -24,7 +24,7 @@ from test import IntegrationTest, client_knobs, unittest
|
||||
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 create_test(scenario_def, test, name):
|
||||
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 @@ class CMAPTestCreator(TestCreator):
|
||||
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()
|
||||
|
||||
|
||||
|
||||
@ -21,7 +21,7 @@ sys.path[0:0] = [""]
|
||||
|
||||
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 create_test(scenario_def, test, name):
|
||||
return run_scenario
|
||||
|
||||
|
||||
test_creator = TestCreator(create_test, TestAllScenarios, _TEST_PATH)
|
||||
test_creator = SpecTestCreator(create_test, TestAllScenarios, _TEST_PATH)
|
||||
test_creator.create_tests()
|
||||
|
||||
|
||||
|
||||
@ -23,7 +23,7 @@ from test import IntegrationTest, client_context, unittest
|
||||
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 create_test(scenario_def, test, name):
|
||||
return run_scenario
|
||||
|
||||
|
||||
TestCreator(create_test, DataLakeTestSpec, _TEST_PATH).create_tests()
|
||||
SpecTestCreator(create_test, DataLakeTestSpec, _TEST_PATH).create_tests()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@ -50,7 +50,7 @@ from test.unified_format import generate_test_classes
|
||||
from test.utils import (
|
||||
AllowListEventListener,
|
||||
OvertCommandListener,
|
||||
TestCreator,
|
||||
SpecTestCreator,
|
||||
TopologyEventListener,
|
||||
camel_to_snake_args,
|
||||
is_greenthread_patched,
|
||||
@ -695,7 +695,7 @@ def create_test(scenario_def, test, name):
|
||||
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()
|
||||
|
||||
|
||||
|
||||
@ -24,7 +24,7 @@ sys.path[0:0] = [""]
|
||||
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 create_operation_test(scenario_def, test, name):
|
||||
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()
|
||||
|
||||
|
||||
|
||||
@ -31,7 +31,7 @@ from test import (
|
||||
from test.utils import (
|
||||
CMAPListener,
|
||||
OvertCommandListener,
|
||||
TestCreator,
|
||||
SpecTestCreator,
|
||||
rs_or_single_client,
|
||||
)
|
||||
from test.utils_spec_runner import SpecRunner
|
||||
@ -138,7 +138,7 @@ def create_test(scenario_def, test, name):
|
||||
return run_scenario
|
||||
|
||||
|
||||
test_creator = TestCreator(create_test, TestSpec, _TEST_PATH)
|
||||
test_creator = SpecTestCreator(create_test, TestSpec, _TEST_PATH)
|
||||
test_creator.create_tests()
|
||||
|
||||
|
||||
|
||||
@ -28,7 +28,7 @@ from test.utils import (
|
||||
DeprecationFilter,
|
||||
EventListener,
|
||||
OvertCommandListener,
|
||||
TestCreator,
|
||||
SpecTestCreator,
|
||||
rs_or_single_client,
|
||||
)
|
||||
from test.utils_spec_runner import SpecRunner
|
||||
@ -120,7 +120,7 @@ def create_test(scenario_def, test, name):
|
||||
return run_scenario
|
||||
|
||||
|
||||
test_creator = TestCreator(create_test, TestAllScenarios, _TEST_PATH)
|
||||
test_creator = SpecTestCreator(create_test, TestAllScenarios, _TEST_PATH)
|
||||
test_creator.create_tests()
|
||||
|
||||
|
||||
|
||||
@ -19,7 +19,7 @@ import threading
|
||||
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 create_test(scenario_def, test, name):
|
||||
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 @@ class CustomTestCreator(TestCreator):
|
||||
return [scenario_def]
|
||||
|
||||
|
||||
CustomTestCreator(create_test, TestAllScenarios, TEST_PATH).create_tests()
|
||||
CustomSpecTestCreator(create_test, TestAllScenarios, TEST_PATH).create_tests()
|
||||
|
||||
|
||||
class FinderThread(threading.Thread):
|
||||
|
||||
@ -23,7 +23,7 @@ sys.path[0:0] = [""]
|
||||
from test import client_context, unittest
|
||||
from test.utils import (
|
||||
OvertCommandListener,
|
||||
TestCreator,
|
||||
SpecTestCreator,
|
||||
rs_client,
|
||||
single_client,
|
||||
wait_until,
|
||||
@ -581,11 +581,11 @@ def create_test(scenario_def, test, name):
|
||||
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()
|
||||
|
||||
|
||||
@ -391,7 +391,7 @@ class FunctionCallRecorder:
|
||||
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):
|
||||
|
||||
34
tox.ini
34
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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user