Skip to content

Commit 0ce7686

Browse files
authored
PYTHON-5563 Fix unified test discovery (#2644)
1 parent f9f48ba commit 0ce7686

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+142
-386
lines changed

test/asynchronous/test_auth_oidc.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
sys.path[0:0] = [""]
3232

33-
from test.asynchronous.unified_format import generate_test_classes
33+
from test.asynchronous.unified_format import generate_test_classes, get_test_path
3434
from test.utils_shared import EventListener, OvertCommandListener
3535

3636
from bson import SON
@@ -54,14 +54,13 @@
5454
_IS_SYNC = False
5555

5656
ROOT = Path(__file__).parent.parent.resolve()
57-
TEST_PATH = ROOT / "auth" / "unified"
5857
ENVIRON = os.environ.get("OIDC_ENV", "test")
5958
DOMAIN = os.environ.get("OIDC_DOMAIN", "")
6059
TOKEN_DIR = os.environ.get("OIDC_TOKEN_DIR", "")
6160
TOKEN_FILE = os.environ.get("OIDC_TOKEN_FILE", "")
6261

6362
# Generate unified tests.
64-
globals().update(generate_test_classes(str(TEST_PATH), module=__name__))
63+
globals().update(generate_test_classes(get_test_path("auth", "unified"), module=__name__))
6564

6665
pytestmark = pytest.mark.auth_oidc
6766

test/asynchronous/test_auth_spec.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,15 @@
2727
sys.path[0:0] = [""]
2828

2929
from test import unittest
30-
from test.asynchronous.unified_format import generate_test_classes
30+
from test.asynchronous.unified_format import generate_test_classes, get_test_path
3131

3232
from pymongo import AsyncMongoClient
3333
from pymongo.auth_oidc_shared import OIDCCallback
3434

3535
pytestmark = pytest.mark.auth
3636

3737
_IS_SYNC = False
38-
39-
_TEST_PATH = os.path.join(os.path.dirname(os.path.realpath(__file__)), "auth")
38+
_TEST_PATH = get_test_path("auth")
4039

4140

4241
class TestAuthSpec(AsyncPyMongoTestCase):

test/asynchronous/test_change_stream.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
async_client_context,
3636
unittest,
3737
)
38-
from test.asynchronous.unified_format import generate_test_classes
38+
from test.asynchronous.unified_format import generate_test_classes, get_test_path
3939
from test.utils_shared import (
4040
AllowListEventListener,
4141
EventListener,
@@ -1143,12 +1143,9 @@ def asyncTearDown(self):
11431143
self.listener.reset()
11441144

11451145

1146-
_TEST_PATH = os.path.join(os.path.dirname(os.path.realpath(__file__)), "change_streams")
1147-
1148-
11491146
globals().update(
11501147
generate_test_classes(
1151-
os.path.join(_TEST_PATH, "unified"),
1148+
get_test_path("change_streams", "unified"),
11521149
module=__name__,
11531150
)
11541151
)

test/asynchronous/test_client_metadata.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import time
2020
import unittest
2121
from test.asynchronous import AsyncIntegrationTest
22-
from test.asynchronous.unified_format import generate_test_classes
22+
from test.asynchronous.unified_format import generate_test_classes, get_test_path
2323
from test.utils_shared import CMAPListener
2424
from typing import Any, Optional
2525

@@ -40,16 +40,8 @@
4040

4141
_IS_SYNC = False
4242

43-
# Location of JSON test specifications.
44-
if _IS_SYNC:
45-
_TEST_PATH = os.path.join(pathlib.Path(__file__).resolve().parent, "handshake", "unified")
46-
else:
47-
_TEST_PATH = os.path.join(
48-
pathlib.Path(__file__).resolve().parent.parent, "handshake", "unified"
49-
)
50-
5143
# Generate unified tests.
52-
globals().update(generate_test_classes(_TEST_PATH, module=__name__))
44+
globals().update(generate_test_classes(get_test_path("handshake", "unified"), module=__name__))
5345

5446

5547
def _get_handshake_driver_info(request):

test/asynchronous/test_collection_management.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,12 @@
2222
sys.path[0:0] = [""]
2323

2424
from test import unittest
25-
from test.asynchronous.unified_format import generate_test_classes
25+
from test.asynchronous.unified_format import generate_test_classes, get_test_path
2626

2727
_IS_SYNC = False
2828

29-
# Location of JSON test specifications.
30-
if _IS_SYNC:
31-
_TEST_PATH = os.path.join(pathlib.Path(__file__).resolve().parent, "collection_management")
32-
else:
33-
_TEST_PATH = os.path.join(
34-
pathlib.Path(__file__).resolve().parent.parent, "collection_management"
35-
)
36-
3729
# Generate unified tests.
38-
globals().update(generate_test_classes(_TEST_PATH, module=__name__))
30+
globals().update(generate_test_classes(get_test_path("collection_management"), module=__name__))
3931

4032
if __name__ == "__main__":
4133
unittest.main()

test/asynchronous/test_command_logging.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,13 @@
2222
sys.path[0:0] = [""]
2323

2424
from test import unittest
25-
from test.asynchronous.unified_format import generate_test_classes
25+
from test.asynchronous.unified_format import generate_test_classes, get_test_path
2626

2727
_IS_SYNC = False
2828

29-
# Location of JSON test specifications.
30-
if _IS_SYNC:
31-
_TEST_PATH = os.path.join(pathlib.Path(__file__).resolve().parent, "command_logging")
32-
else:
33-
_TEST_PATH = os.path.join(pathlib.Path(__file__).resolve().parent.parent, "command_logging")
34-
35-
3629
globals().update(
3730
generate_test_classes(
38-
_TEST_PATH,
31+
get_test_path("command_logging"),
3932
module=__name__,
4033
)
4134
)

test/asynchronous/test_command_monitoring.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,13 @@
2222
sys.path[0:0] = [""]
2323

2424
from test import unittest
25-
from test.asynchronous.unified_format import generate_test_classes
25+
from test.asynchronous.unified_format import generate_test_classes, get_test_path
2626

2727
_IS_SYNC = False
2828

29-
# Location of JSON test specifications.
30-
if _IS_SYNC:
31-
_TEST_PATH = os.path.join(pathlib.Path(__file__).resolve().parent, "command_monitoring")
32-
else:
33-
_TEST_PATH = os.path.join(pathlib.Path(__file__).resolve().parent.parent, "command_monitoring")
34-
35-
3629
globals().update(
3730
generate_test_classes(
38-
_TEST_PATH,
31+
get_test_path("command_monitoring"),
3932
module=__name__,
4033
)
4134
)

test/asynchronous/test_connection_logging.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,13 @@
2222
sys.path[0:0] = [""]
2323

2424
from test import unittest
25-
from test.asynchronous.unified_format import generate_test_classes
25+
from test.asynchronous.unified_format import generate_test_classes, get_test_path
2626

2727
_IS_SYNC = False
2828

29-
# Location of JSON test specifications.
30-
if _IS_SYNC:
31-
_TEST_PATH = os.path.join(pathlib.Path(__file__).resolve().parent, "connection_logging")
32-
else:
33-
_TEST_PATH = os.path.join(pathlib.Path(__file__).resolve().parent.parent, "connection_logging")
34-
35-
3629
globals().update(
3730
generate_test_classes(
38-
_TEST_PATH,
31+
get_test_path("connection_logging"),
3932
module=__name__,
4033
)
4134
)

test/asynchronous/test_crud_unified.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,12 @@
2222
sys.path[0:0] = [""]
2323

2424
from test import unittest
25-
from test.asynchronous.unified_format import generate_test_classes
25+
from test.asynchronous.unified_format import generate_test_classes, get_test_path
2626

2727
_IS_SYNC = False
2828

29-
# Location of JSON test specifications.
30-
if _IS_SYNC:
31-
_TEST_PATH = os.path.join(pathlib.Path(__file__).resolve().parent, "crud", "unified")
32-
else:
33-
_TEST_PATH = os.path.join(pathlib.Path(__file__).resolve().parent.parent, "crud", "unified")
34-
3529
# Generate unified tests.
36-
globals().update(generate_test_classes(_TEST_PATH, module=__name__))
30+
globals().update(generate_test_classes(get_test_path("crud", "unified"), module=__name__))
3731

3832
if __name__ == "__main__":
3933
unittest.main()

test/asynchronous/test_csot.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
sys.path[0:0] = [""]
2323

2424
from test.asynchronous import AsyncIntegrationTest, async_client_context, unittest
25-
from test.asynchronous.unified_format import generate_test_classes
25+
from test.asynchronous.unified_format import generate_test_classes, get_test_path
2626
from test.asynchronous.utils import flaky
2727

2828
import pymongo
@@ -31,14 +31,8 @@
3131

3232
_IS_SYNC = False
3333

34-
# Location of JSON test specifications.
35-
if _IS_SYNC:
36-
TEST_PATH = os.path.join(Path(__file__).resolve().parent, "csot")
37-
else:
38-
TEST_PATH = os.path.join(Path(__file__).resolve().parent.parent, "csot")
39-
4034
# Generate unified tests.
41-
globals().update(generate_test_classes(TEST_PATH, module=__name__))
35+
globals().update(generate_test_classes(get_test_path("csot"), module=__name__))
4236

4337

4438
class TestCSOT(AsyncIntegrationTest):

0 commit comments

Comments
 (0)