| 1 |
# SPDX-License-Identifier: GPL-3.0-or-later |
| 2 |
# Copyright (c) 2008-2026 Andrew Ziem. |
| 3 |
# |
| 4 |
# This work is licensed under the terms of the GNU GPL, version 3 or |
| 5 |
# later. See the COPYING file in the top-level directory. |
| 6 |
|
| 7 |
""" |
| 8 |
Run all test suites |
| 9 |
|
| 10 |
Usage: |
| 11 |
python3 -m tests.TestAll |
| 12 |
""" |
| 13 |
|
| 14 |
import os |
| 15 |
import unittest |
| 16 |
import sys |
| 17 |
import tempfile |
| 18 |
import time |
| 19 |
|
| 20 |
|
| 21 |
try: |
| 22 |
from tests import common |
| 23 |
except ImportError as e: |
| 24 |
print(f'Error importing tests: {e}') |
| 25 |
print('try python3 -m tests.TestAll') |
| 26 |
sys.exit(1) |
| 27 |
|
| 28 |
|
| 29 |
def main(): |
| 30 |
"""Run all tests""" |
| 31 |
print("""You should use the unittest discovery, it's much nicer: |
| 32 |
python -m unittest discover -p Test*.py # run all tests |
| 33 |
python -m unittest tests.TestCLI # run only the CLI tests |
| 34 |
python -m unittest tests.TestCLI.CLITestCase.test_encoding # run only a single test |
| 35 |
|
| 36 |
Or use pytest for more features: |
| 37 |
pytest -n auto tests/ # run all tests in parallel |
| 38 |
pytest tests/TestCLI.py # run only the CLI tests |
| 39 |
pytest tests/TestCLI.py::CLITestCase::test_encoding # run only a single test""") |
| 40 |
|
| 41 |
start_time = time.time() |
| 42 |
with tempfile.TemporaryDirectory(prefix='TestAll ' + __name__) as testdir: |
| 43 |
with common.set_temporary_env('BLEACHBIT_TEST_OPTIONS_DIR', testdir): |
| 44 |
suite = unittest.defaultTestLoader.discover( |
| 45 |
os.getcwd(), pattern='Test*.py') |
| 46 |
success = unittest.TextTestRunner( |
| 47 |
verbosity=2).run(suite).wasSuccessful() |
| 48 |
|
| 49 |
elapsed_time = time.time() - start_time |
| 50 |
minutes = int(elapsed_time // 60) |
| 51 |
seconds = elapsed_time % 60 |
| 52 |
print(f"\nTotal test time: {minutes} minutes {seconds:.2f} seconds") |
| 53 |
sys.exit(success is False) |
| 54 |
|
| 55 |
|
| 56 |
if __name__ == '__main__': |
| 57 |
main() |