|
15 | 15 |
|
16 | 16 | HERE = Path(__file__).absolute().parent
|
17 | 17 | ROOT = HERE.parent.parent
|
18 |
| -DRIVERS_TOOLS = os.environ.get("DRIVERS_TOOLS", "").replace(os.sep, "/") |
19 |
| -PLATFORM = "windows" if os.name == "nt" else sys.platform.lower() |
20 | 18 | AUTH = os.environ.get("AUTH", "noauth")
|
21 | 19 | SSL = os.environ.get("SSL", "nossl")
|
22 | 20 | UV_ARGS = os.environ.get("UV_ARGS", "")
|
|
27 | 25 | LOGGER = logging.getLogger(__name__)
|
28 | 26 | logging.basicConfig(level=logging.INFO, format="%(levelname)-8s %(message)s")
|
29 | 27 |
|
| 28 | +# Handle green frameworks first so they can patch modules. |
| 29 | +if GREEN_FRAMEWORK: |
| 30 | + if GREEN_FRAMEWORK == "eventlet": |
| 31 | + import eventlet |
| 32 | + |
| 33 | + # https://github.com/eventlet/eventlet/issues/401 |
| 34 | + eventlet.sleep() |
| 35 | + eventlet.monkey_patch() |
| 36 | + elif GREEN_FRAMEWORK == "gevent": |
| 37 | + from gevent import monkey |
| 38 | + |
| 39 | + monkey.patch_all() |
| 40 | + |
| 41 | + # Never run async tests with a framework. |
| 42 | + if len(TEST_ARGS) <= 1: |
| 43 | + TEST_ARGS.extend(["-m", "not default_async and default"]) |
| 44 | + else: |
| 45 | + for i in range(len(TEST_ARGS) - 1): |
| 46 | + if "-m" in TEST_ARGS[i]: |
| 47 | + TEST_ARGS[i + 1] = f"not default_async and {TEST_ARGS[i + 1]}" |
| 48 | + |
| 49 | + LOGGER.info(f"Running tests with {GREEN_FRAMEWORK}...") |
| 50 | + |
30 | 51 | # Ensure C extensions if applicable.
|
31 | 52 | if not os.environ.get("NO_EXT") and platform.python_implementation() == "CPython":
|
32 | 53 | sys.path.insert(0, str(ROOT / "tools"))
|
|
41 | 62 | LOGGER.info(f"pymongocrypt version: {pymongocrypt.__version__})")
|
42 | 63 | LOGGER.info(f"libmongocrypt version: {pymongocrypt.libmongocrypt_version()})")
|
43 | 64 |
|
44 |
| -LOGGER.info(f"Running {AUTH} tests over {SSL} with python {sys.executable}") |
45 |
| - |
46 | 65 | # Show the installed packages. Pip can only be run as a cli.
|
47 | 66 | env = os.environ.copy()
|
48 | 67 | env["PIP_QUIET"] = "0"
|
| 68 | +LOGGER.info("Installed packages:") |
49 | 69 | subprocess.run(shlex.split(f"uv run {UV_ARGS} --with pip pip list"), env=env, check=True) # noqa: S603
|
50 | 70 |
|
| 71 | +LOGGER.info(f"Test setup:\n{AUTH=}\n{SSL=}\n{UV_ARGS=}\n{TEST_ARGS=}") |
| 72 | + |
51 | 73 | # Record the start time for a perf test.
|
52 | 74 | if TEST_PERF:
|
53 | 75 | start_time = datetime.now()
|
54 | 76 |
|
55 |
| -# Handle green frameworks. |
56 |
| -if GREEN_FRAMEWORK: |
57 |
| - if GREEN_FRAMEWORK == "eventlet": |
58 |
| - import eventlet |
59 |
| - |
60 |
| - # https://github.com/eventlet/eventlet/issues/401 |
61 |
| - eventlet.sleep() |
62 |
| - eventlet.monkey_patch() |
63 |
| - elif GREEN_FRAMEWORK == "gevent": |
64 |
| - from gevent import monkey |
65 |
| - |
66 |
| - monkey.patch_all() |
67 |
| - |
68 |
| - # Never run async tests with a framework. |
69 |
| - if len(TEST_ARGS) <= 1: |
70 |
| - TEST_ARGS.extend(["-m", "not default_async and default"]) |
71 |
| - else: |
72 |
| - for i in range(len(TEST_ARGS) - 1): |
73 |
| - if "-m" in TEST_ARGS[i]: |
74 |
| - TEST_ARGS[i + 1] = f"not default_async and {TEST_ARGS[i + 1]}" |
75 |
| - |
76 |
| - |
77 | 77 | # Run the tests.
|
78 | 78 | pytest.main(TEST_ARGS)
|
79 | 79 |
|
|
82 | 82 | end_time = datetime.now()
|
83 | 83 | elapsed_secs = (end_time - start_time).total_seconds()
|
84 | 84 | with open("results.json") as fid:
|
85 |
| - print(json.dump(fid, indent=2)) # noqa: T201 |
| 85 | + LOGGER.info("results.json:\n%s", json.dump(fid, indent=2)) |
86 | 86 |
|
87 | 87 | results = dict(
|
88 | 88 | status="pass",
|
|
93 | 93 | elapsed=elapsed_secs,
|
94 | 94 | )
|
95 | 95 | report = dict(failures=0, results=results)
|
96 |
| - print(json.dumps(report, indent=2)) # noqa: T201 |
| 96 | + LOGGER.info("report.json\n%s", json.dumps(report, indent=2)) |
97 | 97 |
|
98 | 98 | with open("report.json", "w", newline="\n") as fid:
|
99 | 99 | json.dump(report, fid)
|
|
0 commit comments