diff --git a/.evergreen/scripts/run_tests.py b/.evergreen/scripts/run_tests.py index 9f700d70e0..8fa3623d66 100644 --- a/.evergreen/scripts/run_tests.py +++ b/.evergreen/scripts/run_tests.py @@ -174,7 +174,7 @@ def run() -> None: return if os.environ.get("DEBUG_LOG"): - TEST_ARGS.extend(f"-o log_cli_level={logging.DEBUG} -o log_cli=1".split()) + TEST_ARGS.extend(f"-o log_cli_level={logging.DEBUG}".split()) # Run local tests. ret = pytest.main(TEST_ARGS + sys.argv[1:]) diff --git a/.evergreen/scripts/setup_tests.py b/.evergreen/scripts/setup_tests.py index 9b657507c1..058e86a805 100644 --- a/.evergreen/scripts/setup_tests.py +++ b/.evergreen/scripts/setup_tests.py @@ -465,9 +465,7 @@ def handle_test_env() -> None: UV_ARGS.append(f"--group {framework}") else: - # Use --capture=tee-sys so pytest prints test output inline: - # https://docs.pytest.org/en/stable/how-to/capture-stdout-stderr.html - TEST_ARGS = f"-v --capture=tee-sys --durations=5 {TEST_ARGS}" + TEST_ARGS = f"-v --durations=5 {TEST_ARGS}" TEST_SUITE = TEST_SUITE_MAP.get(test_name) if TEST_SUITE: TEST_ARGS = f"-m {TEST_SUITE} {TEST_ARGS}" diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 60583022b7..12e6f0cd0e 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -351,11 +351,11 @@ If you are running one of the `no-responder` tests, omit the `run-server` step. ## Enable Debug Logs -- Use `-o log_cli_level="DEBUG" -o log_cli=1` with `just test` or `pytest`. -- Add `log_cli_level = "DEBUG` and `log_cli = 1` to the `tool.pytest.ini_options` section in `pyproject.toml` for Evergreen patches or to enable debug logs by default on your machine. -- You can also set `DEBUG_LOG=1` and run either `just setup-tests` or `just-test`. +- Use `-o log_cli_level="DEBUG" -o log_cli=1` with `just test` or `pytest` to output all debug logs to the terminal. **Warning**: This will output a huge amount of logs. +- Add `log_cli=1` and `log_cli_level="DEBUG"` to the `tool.pytest.ini_options` section in `pyproject.toml` to enable debug logs in this manner by default on your machine. +- Set `DEBUG_LOG=1` and run `just setup-tests`, `just-test`, or `pytest` to enable debug logs only for failed tests. - Finally, you can use `just setup-tests --debug-log`. -- For evergreen patch builds, you can use `evergreen patch --param DEBUG_LOG=1` to enable debug logs for the patch. +- For evergreen patch builds, you can use `evergreen patch --param DEBUG_LOG=1` to enable debug logs for failed tests in the patch. ## Adding a new test suite diff --git a/test/asynchronous/test_client.py b/test/asynchronous/test_client.py index c9cfca81fc..143cccc3c8 100644 --- a/test/asynchronous/test_client.py +++ b/test/asynchronous/test_client.py @@ -34,7 +34,7 @@ import time import uuid from typing import Any, Iterable, Type, no_type_check -from unittest import mock +from unittest import mock, skipIf from unittest.mock import patch import pytest @@ -629,6 +629,7 @@ def test_detected_environment_logging(self, mock_get_hosts): logs = [record.getMessage() for record in cm.records if record.name == "pymongo.client"] self.assertEqual(len(logs), 7) + @skipIf(os.environ.get("DEBUG_LOG"), "Enabling debug logs breaks this test") @patch("pymongo.asynchronous.srv_resolver._SrvResolver.get_hosts") async def test_detected_environment_warning(self, mock_get_hosts): with self._caplog.at_level(logging.WARN): diff --git a/test/test_client.py b/test/test_client.py index 038ba2241b..8ef95699ca 100644 --- a/test/test_client.py +++ b/test/test_client.py @@ -34,7 +34,7 @@ import time import uuid from typing import Any, Iterable, Type, no_type_check -from unittest import mock +from unittest import mock, skipIf from unittest.mock import patch import pytest @@ -622,6 +622,7 @@ def test_detected_environment_logging(self, mock_get_hosts): logs = [record.getMessage() for record in cm.records if record.name == "pymongo.client"] self.assertEqual(len(logs), 7) + @skipIf(os.environ.get("DEBUG_LOG"), "Enabling debug logs breaks this test") @patch("pymongo.synchronous.srv_resolver._SrvResolver.get_hosts") def test_detected_environment_warning(self, mock_get_hosts): with self._caplog.at_level(logging.WARN):