test_logger.py 698 B

12345678910111213141516171819202122232425
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. """Created on Thu Apr 04 2024 16:57:34 by codeskyblue
  4. """
  5. import logging
  6. import pytest
  7. from uiautomator2 import enable_pretty_logging
  8. def test_enable_pretty_logging(caplog: pytest.LogCaptureFixture):
  9. logger = logging.getLogger("uiautomator2")
  10. logger.info("should not be printed")
  11. enable_pretty_logging()
  12. logger.info("hello")
  13. enable_pretty_logging(logging.INFO)
  14. logger.info("world")
  15. logger.debug("should not be printed")
  16. # Use caplog.text to check the entire log output as a single string
  17. assert "hello" in caplog.text
  18. assert "world" in caplog.text
  19. assert "should not be printed" not in caplog.text