test_crash.py (1038B)
1 #!/usr/bin/env python 2 # This Source Code Form is subject to the terms of the Mozilla Public 3 # License, v. 2.0. If a copy of the MPL was not distributed with this file, 4 # You can obtain one at http://mozilla.org/MPL/2.0/. 5 6 from unittest.mock import patch 7 8 import mozunit 9 import pytest 10 11 12 @pytest.mark.parametrize("logger", [True, False]) 13 def test_crash_count_with_or_without_logger(runner, logger): 14 if runner.app == "chrome": 15 pytest.xfail("crash checking not implemented for ChromeRunner") 16 17 if not logger: 18 runner.logger = None 19 fn = "check_for_crashes" 20 else: 21 fn = "log_crashes" 22 23 with patch(f"mozcrash.{fn}", return_value=2) as mock: 24 assert runner.crashed == 0 25 assert runner.check_for_crashes() == 2 26 assert runner.crashed == 2 27 assert runner.check_for_crashes() == 2 28 assert runner.crashed == 4 29 30 mock.return_value = 0 31 assert runner.check_for_crashes() == 0 32 assert runner.crashed == 4 33 34 35 if __name__ == "__main__": 36 mozunit.main()