From 9b45922ea51115bf8851bcca7c09fe4968cce529 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20St=C3=B6neberg?= Date: Sun, 15 Dec 2024 14:24:45 +0100 Subject: [PATCH] use `pytest-xdist` to utilize multiple workers for Python tests (#6696) --- .github/workflows/CI-unixish.yml | 16 +++-- .github/workflows/CI-windows.yml | 7 +- .github/workflows/asan.yml | 7 +- .github/workflows/scriptcheck.yml | 7 +- .github/workflows/tsan.yml | 7 +- .github/workflows/ubsan.yml | 7 +- addons/test/misra_test.py | 1 + test/cli/other_test.py | 110 +++++++++++++++--------------- 8 files changed, 88 insertions(+), 74 deletions(-) diff --git a/.github/workflows/CI-unixish.yml b/.github/workflows/CI-unixish.yml index 70c354a53bd..ebb2950733a 100644 --- a/.github/workflows/CI-unixish.yml +++ b/.github/workflows/CI-unixish.yml @@ -268,6 +268,11 @@ jobs: strategy: matrix: os: [ubuntu-20.04, ubuntu-22.04, macos-13] + include: + - xdist_n: auto + # FIXME: test_color_tty fails with xdist + - os: macos-13 + xdist_n: '1' fail-fast: false # Prefer quick result runs-on: ${{ matrix.os }} @@ -306,6 +311,7 @@ jobs: python3 -m pip install pip --upgrade python3 -m pip install pytest python3 -m pip install pytest-timeout + python3 -m pip install pytest-xdist python3 -m pip install psutil - name: Build cppcheck @@ -329,7 +335,7 @@ jobs: - name: Run test/cli run: | - python3 -m pytest -Werror --strict-markers -vv test/cli + python3 -m pytest -Werror --strict-markers -vv -n ${{ matrix.xdist_n }} test/cli # TODO: use the step below instead # do not use pushd in this step since we go below the working directory @@ -338,7 +344,7 @@ jobs: cd .. ln -s cppcheck 'cpp check' cd 'cpp check/test/cli' - python3 -m pytest -Werror --strict-markers -vv + python3 -m pytest -Werror --strict-markers -vv -n ${{ matrix.xdist_n }} # FIXME: proj2_test.py fails because of the relative path cleanups in ImportProject::setRelativePaths() # It fails because the application path used as base path has its symlink resolved by getcwd(). @@ -346,18 +352,18 @@ jobs: if: false run: | ln -s . 'cpp check' - python3 -m pytest -Werror --strict-markers -vv 'cpp check/test/cli' + python3 -m pytest -Werror --strict-markers -vv -n ${{ matrix.xdist_n }} 'cpp check/test/cli' - name: Run test/cli (-j2) run: | - python3 -m pytest -Werror --strict-markers -vv test/cli + python3 -m pytest -Werror --strict-markers -vv -n ${{ matrix.xdist_n }} test/cli env: TEST_CPPCHECK_INJECT_J: 2 - name: Run test/cli (--clang) if: false run: | - python3 -m pytest -Werror --strict-markers -vv test/cli + python3 -m pytest -Werror --strict-markers -vv -n ${{ matrix.xdist_n }} test/cli env: TEST_CPPCHECK_INJECT_CLANG: clang diff --git a/.github/workflows/CI-windows.yml b/.github/workflows/CI-windows.yml index 0cf5dd1898d..18ccaf3bbf7 100644 --- a/.github/workflows/CI-windows.yml +++ b/.github/workflows/CI-windows.yml @@ -143,6 +143,7 @@ jobs: python -m pip install pytest || exit /b !errorlevel! python -m pip install pytest-custom_exit_code || exit /b !errorlevel! python -m pip install pytest-timeout || exit /b !errorlevel! + python -m pip install pytest-xdist || exit /b !errorlevel! python -m pip install psutil || exit /b !errorlevel! # TODO: build with CMake @@ -182,12 +183,12 @@ jobs: - name: Run test/cli if: matrix.config == 'release' run: | - python -m pytest -Werror --strict-markers -vv test/cli || exit /b !errorlevel! + python -m pytest -Werror --strict-markers -vv -n auto test/cli || exit /b !errorlevel! - name: Run test/cli (-j2) if: matrix.config == 'release' run: | - python -m pytest -Werror --strict-markers -vv test/cli || exit /b !errorlevel! + python -m pytest -Werror --strict-markers -vv -n auto test/cli || exit /b !errorlevel! env: TEST_CPPCHECK_INJECT_J: 2 @@ -195,7 +196,7 @@ jobs: - name: Run test/cli (--clang) if: false # matrix.config == 'release' run: | - python -m pytest -Werror --strict-markers -vv test/cli || exit /b !errorlevel! + python -m pytest -Werror --strict-markers -vv -n auto test/cli || exit /b !errorlevel! env: TEST_CPPCHECK_INJECT_CLANG: clang diff --git a/.github/workflows/asan.yml b/.github/workflows/asan.yml index e7fa9f09fc6..f01898ef533 100644 --- a/.github/workflows/asan.yml +++ b/.github/workflows/asan.yml @@ -67,6 +67,7 @@ jobs: python3 -m pip install pip --upgrade python3 -m pip install pytest python3 -m pip install pytest-timeout + python3 -m pip install pytest-xdist python3 -m pip install psutil # TODO: disable all warnings @@ -103,12 +104,12 @@ jobs: - name: Run test/cli run: | pwd=$(pwd) - TEST_CPPCHECK_EXE_LOOKUP_PATH="$pwd/cmake.output" python3 -m pytest -Werror --strict-markers -vv test/cli + TEST_CPPCHECK_EXE_LOOKUP_PATH="$pwd/cmake.output" python3 -m pytest -Werror --strict-markers -vv -n auto test/cli - name: Run test/cli (-j2) run: | pwd=$(pwd) - TEST_CPPCHECK_EXE_LOOKUP_PATH="$pwd/cmake.output" python3 -m pytest -Werror --strict-markers -vv test/cli + TEST_CPPCHECK_EXE_LOOKUP_PATH="$pwd/cmake.output" python3 -m pytest -Werror --strict-markers -vv -n auto test/cli env: TEST_CPPCHECK_INJECT_J: 2 @@ -116,7 +117,7 @@ jobs: if: false run: | pwd=$(pwd) - TEST_CPPCHECK_EXE_LOOKUP_PATH="$pwd/cmake.output" python3 -m pytest -Werror --strict-markers -vv test/cli + TEST_CPPCHECK_EXE_LOOKUP_PATH="$pwd/cmake.output" python3 -m pytest -Werror --strict-markers -vv -n auto test/cli env: TEST_CPPCHECK_INJECT_CLANG: clang diff --git a/.github/workflows/scriptcheck.yml b/.github/workflows/scriptcheck.yml index bd30ce6fac4..df25c41688f 100644 --- a/.github/workflows/scriptcheck.yml +++ b/.github/workflows/scriptcheck.yml @@ -92,6 +92,7 @@ jobs: python -m pip install 'pylint<=3.3.0' python -m pip install unittest2 python -m pip install pytest + python -m pip install pytest-xdist python -m pip install pygments python -m pip install requests python -m pip install psutil @@ -135,18 +136,20 @@ jobs: run: | python tools/test_matchcompiler.py + # TODO: run with "-n auto" when misra_test.py can be run in parallel # we cannot specify -Werror since xml/etree/ElementTree.py in Python 3.9/3.10 contains an unclosed file - name: test addons if: matrix.python-version == '3.9' || matrix.python-version == '3.10' run: | - python -m pytest --strict-markers -vv addons/test + python -m pytest --strict-markers -vv -n 1 addons/test env: PYTHONPATH: ./addons + # TODO: run with "-n auto" when misra_test.py can be run in parallel - name: test addons if: matrix.python-version != '3.9' && matrix.python-version != '3.10' run: | - python -m pytest -Werror --strict-markers -vv addons/test + python -m pytest -Werror --strict-markers -vv -n 1 addons/test env: PYTHONPATH: ./addons diff --git a/.github/workflows/tsan.yml b/.github/workflows/tsan.yml index d0f3fd9ff5e..8651983ae2d 100644 --- a/.github/workflows/tsan.yml +++ b/.github/workflows/tsan.yml @@ -67,6 +67,7 @@ jobs: python3 -m pip install pip --upgrade python3 -m pip install pytest python3 -m pip install pytest-timeout + python3 -m pip install pytest-xdist python3 -m pip install psutil - name: CMake @@ -103,14 +104,14 @@ jobs: - name: Run test/cli run: | pwd=$(pwd) - TEST_CPPCHECK_EXE_LOOKUP_PATH="$pwd/cmake.output" python3 -m pytest -Werror --strict-markers -vv test/cli + TEST_CPPCHECK_EXE_LOOKUP_PATH="$pwd/cmake.output" python3 -m pytest -Werror --strict-markers -vv -n auto test/cli env: TEST_CPPCHECK_INJECT_EXECUTOR: thread - name: Run test/cli (-j2) run: | pwd=$(pwd) - TEST_CPPCHECK_EXE_LOOKUP_PATH="$pwd/cmake.output" python3 -m pytest -Werror --strict-markers -vv test/cli + TEST_CPPCHECK_EXE_LOOKUP_PATH="$pwd/cmake.output" python3 -m pytest -Werror --strict-markers -vv -n auto test/cli env: TEST_CPPCHECK_INJECT_J: 2 @@ -118,7 +119,7 @@ jobs: if: false run: | pwd=$(pwd) - TEST_CPPCHECK_EXE_LOOKUP_PATH="$pwd/cmake.output" python3 -m pytest -Werror --strict-markers -vv test/cli + TEST_CPPCHECK_EXE_LOOKUP_PATH="$pwd/cmake.output" python3 -m pytest -Werror --strict-markers -vv -n auto test/cli env: TEST_CPPCHECK_INJECT_CLANG: clang diff --git a/.github/workflows/ubsan.yml b/.github/workflows/ubsan.yml index e60942c8e0e..cab77d1489a 100644 --- a/.github/workflows/ubsan.yml +++ b/.github/workflows/ubsan.yml @@ -67,6 +67,7 @@ jobs: python3 -m pip install pip --upgrade python3 -m pip install pytest python3 -m pip install pytest-timeout + python3 -m pip install pytest-xdist python3 -m pip install psutil # TODO: disable warnings @@ -103,12 +104,12 @@ jobs: - name: Run test/cli run: | pwd=$(pwd) - TEST_CPPCHECK_EXE_LOOKUP_PATH="$pwd/cmake.output" python3 -m pytest -Werror --strict-markers -vv test/cli + TEST_CPPCHECK_EXE_LOOKUP_PATH="$pwd/cmake.output" python3 -m pytest -Werror --strict-markers -vv -n auto test/cli - name: Run test/cli (-j2) run: | pwd=$(pwd) - TEST_CPPCHECK_EXE_LOOKUP_PATH="$pwd/cmake.output" python3 -m pytest -Werror --strict-markers -vv test/cli + TEST_CPPCHECK_EXE_LOOKUP_PATH="$pwd/cmake.output" python3 -m pytest -Werror --strict-markers -vv -n auto test/cli env: TEST_CPPCHECK_INJECT_J: 2 @@ -116,7 +117,7 @@ jobs: if: false run: | pwd=$(pwd) - TEST_CPPCHECK_EXE_LOOKUP_PATH="$pwd/cmake.output" python3 -m pytest -Werror --strict-markers -vv test/cli + TEST_CPPCHECK_EXE_LOOKUP_PATH="$pwd/cmake.output" python3 -m pytest -Werror --strict-markers -vv -n auto test/cli env: TEST_CPPCHECK_INJECT_CLANG: clang diff --git a/addons/test/misra_test.py b/addons/test/misra_test.py index 6afd0f6ed09..9862318d30b 100644 --- a/addons/test/misra_test.py +++ b/addons/test/misra_test.py @@ -30,6 +30,7 @@ def checker(): return MisraChecker(settings) +# FIXME: files are generates in the source tree so it will cause issues if tests are run with xdist. @pytest.fixture def test_files(): for f in TEST_SOURCE_FILES: diff --git a/test/cli/other_test.py b/test/cli/other_test.py index 9e391683223..b5fbe73f9e9 100644 --- a/test/cli/other_test.py +++ b/test/cli/other_test.py @@ -98,9 +98,9 @@ def test_color_non_tty(tmpdir, env, color_expected): test_file = os.path.join(tmpdir, 'test.c') with open(test_file, 'wt') as f: f.write('#error test\nx=1;\n') - exitcode, _, stderr = cppcheck([test_file], env=env) + exitcode, stdout, stderr = cppcheck([test_file], env=env) - assert exitcode == 0 + assert exitcode == 0, stdout if stdout else stderr assert stderr assert (__ANSI_BOLD in stderr) == color_expected assert (__ANSI_FG_RED in stderr) == color_expected @@ -114,9 +114,9 @@ def test_color_tty(tmpdir, env, color_expected): test_file = os.path.join(tmpdir, 'test.c') with open(test_file, 'wt') as f: f.write('#error test\nx=1;\n') - exitcode, _, stderr = cppcheck([test_file], env=env, tty=True) + exitcode, stdout, stderr = cppcheck([test_file], env=env, tty=True) - assert exitcode == 0 + assert exitcode == 0, stdout if stdout else stderr assert stderr assert (__ANSI_BOLD in stderr) == color_expected assert (__ANSI_FG_RED in stderr) == color_expected @@ -159,7 +159,7 @@ def test_progress(tmpdir): args = ['--report-progress=0', '--enable=all', '--inconclusive', '-j1', test_file] exitcode, stdout, stderr = cppcheck(args) - assert exitcode == 0 + assert exitcode == 0, stdout if stdout else stderr pos = stdout.find('\n') assert(pos != -1) pos += 1 @@ -192,7 +192,7 @@ def test_progress_j(tmpdir): args = ['--report-progress=0', '--enable=all', '--inconclusive', '-j2', '--disable=unusedFunction', test_file] exitcode, stdout, stderr = cppcheck(args) - assert exitcode == 0 + assert exitcode == 0, stdout if stdout else stderr assert stdout == "Checking {} ...\n".format(test_file) assert stderr == "" @@ -282,7 +282,7 @@ def test_addon_misra(tmpdir): args = ['--addon=misra', '--enable=all', '--disable=unusedFunction', '-j1', test_file] exitcode, stdout, stderr = cppcheck(args) - assert exitcode == 0 + assert exitcode == 0, stdout if stdout else stderr lines = stdout.splitlines() assert lines == [ 'Checking {} ...'.format(test_file) @@ -305,7 +305,7 @@ def test_addon_y2038(tmpdir): args = ['--addon=y2038', '--enable=all', '--disable=unusedFunction', '--template=simple', test_file] exitcode, stdout, stderr = cppcheck(args) - assert exitcode == 0 + assert exitcode == 0, stdout if stdout else stderr lines = stdout.splitlines() assert lines == [ 'Checking {} ...'.format(test_file) @@ -326,7 +326,7 @@ def test_addon_threadsafety(tmpdir): args = ['--addon=threadsafety', '--enable=all', '--disable=unusedFunction', '--template=simple', test_file] exitcode, stdout, stderr = cppcheck(args) - assert exitcode == 0 + assert exitcode == 0, stdout if stdout else stderr lines = stdout.splitlines() assert lines == [ 'Checking {} ...'.format(test_file) @@ -356,7 +356,7 @@ def test_addon_naming(tmpdir): args = ['--addon={}'.format(addon_file), '--enable=all', '--disable=unusedFunction', '--template=simple', test_file] exitcode, stdout, stderr = cppcheck(args) - assert exitcode == 0 + assert exitcode == 0, stdout if stdout else stderr lines = stdout.splitlines() assert lines == [ 'Checking {} ...'.format(test_file) @@ -467,7 +467,7 @@ class _clz { args = ['--addon='+addon_file, '--verbose', '--enable=all', '--disable=unusedFunction', test_file] exitcode, stdout, stderr = cppcheck(args) - assert exitcode == 0 + assert exitcode == 0, stdout if stdout else stderr lines = __remove_verbose_log(stdout.splitlines()) assert lines == [ 'Checking {} ...'.format(test_file) @@ -595,7 +595,7 @@ def test_addon_namingng_config(tmpdir): args = ['--addon='+addon_file, '--verbose', '--enable=all', '-j1', test_file] exitcode, stdout, stderr = cppcheck(args) - assert exitcode == 0 + assert exitcode == 0, stdout if stdout else stderr lines = __remove_verbose_log(stdout.splitlines()) assert lines == [ @@ -641,7 +641,7 @@ def test_addon_findcasts(tmpdir): args = ['--addon=findcasts', '--enable=all', '--disable=unusedFunction', '--template=simple', test_file] exitcode, stdout, stderr = cppcheck(args) - assert exitcode == 0 + assert exitcode == 0, stdout if stdout else stderr lines = stdout.splitlines() assert lines == [ 'Checking {} ...'.format(test_file) @@ -662,7 +662,7 @@ def test_addon_misc(tmpdir): args = ['--addon=misc', '--enable=all', '--disable=unusedFunction', '--template=simple', test_file] exitcode, stdout, stderr = cppcheck(args) - assert exitcode == 0 + assert exitcode == 0, stdout if stdout else stderr lines = stdout.splitlines() assert lines == [ 'Checking {} ...'.format(test_file) @@ -938,7 +938,7 @@ def test_file_order(tmpdir): args = [test_file_c, test_file_d, test_file_b, test_file_a, '-j1'] exitcode, stdout, stderr = cppcheck(args) - assert exitcode == 0 + assert exitcode == 0, stdout if stdout else stderr lines = stdout.splitlines() assert lines == [ 'Checking {} ...'.format(test_file_c), @@ -999,7 +999,7 @@ def test_markup_j(tmpdir): args = ['--library=qt', '-j2', test_file_1, test_file_2, test_file_3, test_file_4] exitcode, stdout, stderr = cppcheck(args) - assert exitcode == 0 + assert exitcode == 0, stdout if stdout else stderr lines = stdout.splitlines() for i in range(1, 5): lines.remove('{}/4 files checked 0% done'.format(i)) @@ -1056,7 +1056,7 @@ def test_valueflow_debug(tmpdir): args = ['--debug', test_file_cpp] exitcode, stdout, stderr = cppcheck(args) - assert exitcode == 0 + assert exitcode == 0, stdout if stdout else stderr if sys.platform == "win32": stdout = stdout.replace('/', '\\') assert stdout == '''Checking {} ... @@ -1114,7 +1114,7 @@ def test_file_duplicate(tmpdir): args = [test_file_a, test_file_a, str(tmpdir)] exitcode, stdout, stderr = cppcheck(args) - assert exitcode == 0 + assert exitcode == 0, stdout if stdout else stderr lines = stdout.splitlines() assert lines == [ 'Checking {} ...'.format(test_file_a) @@ -1136,7 +1136,7 @@ def test_file_duplicate_2(tmpdir): args = [test_file_c, test_file_a, test_file_b, str(tmpdir), test_file_b, test_file_c, test_file_a, str(tmpdir), '-j1'] exitcode, stdout, stderr = cppcheck(args) - assert exitcode == 0 + assert exitcode == 0, stdout if stdout else stderr lines = stdout.splitlines() assert lines == [ 'Checking {} ...'.format(test_file_c), @@ -1166,7 +1166,7 @@ def test_file_duplicate_3(tmpdir): args.append('-j1') # TODO: remove when fixed exitcode, stdout, stderr = cppcheck(args, cwd=tmpdir) - assert exitcode == 0 + assert exitcode == 0, stdout if stdout else stderr lines = stdout.splitlines() # TODO: only a single file should be checked if sys.platform == 'win32': @@ -1220,7 +1220,7 @@ def test_file_duplicate_4(tmpdir): args.append('-j1') # TODO: remove when fixed exitcode, stdout, stderr = cppcheck(args, cwd=tmpdir) - assert exitcode == 0 + assert exitcode == 0, stdout if stdout else stderr lines = stdout.splitlines() # TODO: only a single file should be checked assert lines == [ @@ -1331,7 +1331,7 @@ def test_unknown_extension(tmpdir): ''') exitcode, stdout, stderr = cppcheck(['-q', test_file]) - assert exitcode == 0, stderr + assert exitcode == 0, stdout if stdout else stderr assert stdout == '' assert stderr == '' @@ -1369,7 +1369,7 @@ def test_rule_file_define_multiple(tmpdir): ''') exitcode, stdout, stderr = cppcheck(['--template=simple', '--rule-file={}'.format(rule_file), '-DDEF_3', test_file]) - assert exitcode == 0, stderr + assert exitcode == 0, stdout if stdout else stderr lines = stdout.splitlines() assert lines == [ 'Checking {} ...'.format(test_file), @@ -1403,7 +1403,7 @@ def test_rule_file_define(tmpdir): ''') exitcode, stdout, stderr = cppcheck(['--template=simple', '--rule-file={}'.format(rule_file), '-DDEF_3', test_file]) - assert exitcode == 0, stdout + assert exitcode == 0, stdout if stdout else stderr lines = stdout.splitlines() assert lines == [ 'Checking {} ...'.format(test_file), @@ -1436,7 +1436,7 @@ def test_rule_file_normal(tmpdir): ''') exitcode, stdout, stderr = cppcheck(['--template=simple', '--rule-file={}'.format(rule_file), test_file]) - assert exitcode == 0, stdout + assert exitcode == 0, stdout if stdout else stderr lines = stdout.splitlines() assert lines == [ 'Checking {} ...'.format(test_file), @@ -1468,7 +1468,7 @@ def test_rule_file_raw(tmpdir): ''') exitcode, stdout, stderr = cppcheck(['--template=simple', '--rule-file={}'.format(rule_file), test_file]) - assert exitcode == 0, stdout + assert exitcode == 0, stdout if stdout else stderr lines = stdout.splitlines() assert lines == [ 'Checking {} ...'.format(test_file), @@ -1491,7 +1491,7 @@ def test_rule(tmpdir): ''') exitcode, stdout, stderr = cppcheck(['--template=simple', '--rule=f', test_file]) - assert exitcode == 0, stdout + assert exitcode == 0, stdout if stdout else stderr lines = stdout.splitlines() assert lines == [ 'Checking {} ...'.format(test_file), @@ -1548,9 +1548,9 @@ def test_filelist(tmpdir): pass # TODO: -rp is not applied to "Checking" messages - #exitcode, stdout, _ = cppcheck(['-j1', '-rp', list_dir]) - exitcode, stdout, _ = cppcheck(['-j1', '.'], cwd=list_dir) - assert exitcode == 0, stdout + #exitcode, stdout, stderr = cppcheck(['-j1', '-rp', list_dir]) + exitcode, stdout, stderr = cppcheck(['-j1', '.'], cwd=list_dir) + assert exitcode == 0, stdout if stdout else stderr if sys.platform == "win32": stdout = stdout.replace('\\', '/') lines = stdout.splitlines() @@ -1591,8 +1591,8 @@ def test_markup_lang(tmpdir): test_file_2 ] - exitcode, stdout, _ = cppcheck(args) - assert exitcode == 0, stdout + exitcode, stdout, stderr = cppcheck(args) + assert exitcode == 0, stdout if stdout else stderr def test_cpp_probe(tmpdir): @@ -1605,7 +1605,7 @@ def test_cpp_probe(tmpdir): args = ['-q', '--template=simple', '--cpp-header-probe', '--verbose', test_file] exitcode, stdout, stderr = cppcheck(args) - assert exitcode == 0, stdout + assert exitcode == 0, stdout if stdout else stderr lines = stdout.splitlines() assert lines == [] lines = stderr.splitlines() @@ -1634,11 +1634,11 @@ def test_lib_lookup(tmpdir): with open(test_file, 'wt'): pass - exitcode, stdout, _, exe = cppcheck_ex(['--debug-lookup=library', '--library=gnu', test_file]) + exitcode, stdout, stderr, exe = cppcheck_ex(['--debug-lookup=library', '--library=gnu', test_file]) exepath = os.path.dirname(exe) if sys.platform == 'win32': exepath = exepath.replace('\\', '/') - assert exitcode == 0, stdout + assert exitcode == 0, stdout if stdout else stderr lines = __remove_std_lookup_log(stdout.splitlines(), exepath) assert lines == [ "looking for library 'gnu'", @@ -1687,11 +1687,11 @@ def test_lib_lookup_absolute(tmpdir): ''') - exitcode, stdout, _, exe = cppcheck_ex(['--debug-lookup=library', '--library={}'.format(cfg_file), test_file]) + exitcode, stdout, stderr, exe = cppcheck_ex(['--debug-lookup=library', '--library={}'.format(cfg_file), test_file]) exepath = os.path.dirname(exe) if sys.platform == 'win32': exepath = exepath.replace('\\', '/') - assert exitcode == 0, stdout + assert exitcode == 0, stdout if stdout else stderr lines = __remove_std_lookup_log(stdout.splitlines(), exepath) assert lines == [ "looking for library '{}'".format(cfg_file), @@ -1730,11 +1730,11 @@ def test_lib_lookup_nofile(tmpdir): gtk_cfg_dir = os.path.join(tmpdir, 'gtk.cfg') os.mkdir(gtk_cfg_dir) - exitcode, stdout, _, exe = cppcheck_ex(['--debug-lookup=library', '--library=gtk', test_file], cwd=tmpdir) + exitcode, stdout, stderr, exe = cppcheck_ex(['--debug-lookup=library', '--library=gtk', test_file], cwd=tmpdir) exepath = os.path.dirname(exe) if sys.platform == 'win32': exepath = exepath.replace('\\', '/') - assert exitcode == 0, stdout + assert exitcode == 0, stdout if stdout else stderr lines = __remove_std_lookup_log(stdout.splitlines(), exepath) assert lines == [ "looking for library 'gtk'", @@ -1750,11 +1750,11 @@ def test_lib_lookup_multi(tmpdir): with open(test_file, 'wt'): pass - exitcode, stdout, _, exe = cppcheck_ex(['--debug-lookup=library', '--library=posix,gnu', test_file]) + exitcode, stdout, stderr, exe = cppcheck_ex(['--debug-lookup=library', '--library=posix,gnu', test_file]) exepath = os.path.dirname(exe) if sys.platform == 'win32': exepath = exepath.replace('\\', '/') - assert exitcode == 0, stdout + assert exitcode == 0, stdout if stdout else stderr lines = __remove_std_lookup_log(stdout.splitlines(), exepath) assert lines == [ "looking for library 'posix'", @@ -1774,8 +1774,8 @@ def test_platform_lookup_builtin(tmpdir): with open(test_file, 'wt'): pass - exitcode, stdout, _ = cppcheck(['--debug-lookup=platform', '--platform=unix64', test_file]) - assert exitcode == 0, stdout + exitcode, stdout, stderr = cppcheck(['--debug-lookup=platform', '--platform=unix64', test_file]) + assert exitcode == 0, stdout if stdout else stderr lines = stdout.splitlines() # built-in platform are not being looked up assert lines == [ @@ -1791,11 +1791,11 @@ def test_platform_lookup_external(tmpdir): with open(test_file, 'wt'): pass - exitcode, stdout, _, exe = cppcheck_ex(['--debug-lookup=platform', '--platform=avr8', test_file]) + exitcode, stdout, stderr, exe = cppcheck_ex(['--debug-lookup=platform', '--platform=avr8', test_file]) exepath = os.path.dirname(exe) if sys.platform == 'win32': exepath = exepath.replace('\\', '/') - assert exitcode == 0, stdout + assert exitcode == 0, stdout if stdout else stderr lines = stdout.splitlines() assert lines == [ "looking for platform 'avr8' in '{}'".format(os.path.join(exepath, 'cppcheck')), # TODO: this not not the path *of* the executable but the the path *to* the executable @@ -1841,10 +1841,10 @@ def test_addon_lookup(tmpdir): with open(test_file, 'wt'): pass - exitcode, stdout, _, exe = cppcheck_ex(['--debug-lookup=addon', '--addon=misra', test_file]) + exitcode, stdout, stderr, exe = cppcheck_ex(['--debug-lookup=addon', '--addon=misra', test_file]) exepath = os.path.dirname(exe) exepath_sep = exepath + os.path.sep - assert exitcode == 0, stdout + assert exitcode == 0, stdout if stdout else stderr lines = stdout.splitlines() assert lines == [ "looking for addon 'misra.py'", @@ -1860,10 +1860,10 @@ def test_addon_lookup_ext(tmpdir): with open(test_file, 'wt'): pass - exitcode, stdout, _, exe = cppcheck_ex(['--debug-lookup=addon', '--addon=misra.py', test_file]) + exitcode, stdout, stderr, exe = cppcheck_ex(['--debug-lookup=addon', '--addon=misra.py', test_file]) exepath = os.path.dirname(exe) exepath_sep = exepath + os.path.sep - assert exitcode == 0, stdout + assert exitcode == 0, stdout if stdout else stderr lines = stdout.splitlines() assert lines == [ "looking for addon 'misra.py'", @@ -1923,10 +1923,10 @@ def test_config_lookup(tmpdir): with open(config_file, 'wt'): pass - exitcode, stdout, _, exe = cppcheck_ex(['--debug-lookup=config', '--addon=misra', test_file], cwd=tmpdir) + exitcode, stdout, stderr, exe = cppcheck_ex(['--debug-lookup=config', '--addon=misra', test_file], cwd=tmpdir) exepath = os.path.dirname(exe) exepath_sep = exepath + os.path.sep - assert exitcode == 0, stdout + assert exitcode == 0, stdout if stdout else stderr lines = stdout.splitlines() assert lines == [ "looking for '{}cppcheck.cfg'".format(exepath_sep), @@ -1941,10 +1941,10 @@ def test_config_lookup_notfound(tmpdir): with open(test_file, 'wt'): pass - exitcode, stdout, _, exe = cppcheck_ex(['--debug-lookup=config', test_file]) + exitcode, stdout, stderr, exe = cppcheck_ex(['--debug-lookup=config', test_file]) exepath = os.path.dirname(exe) exepath_sep = exepath + os.path.sep - assert exitcode == 0, stdout + assert exitcode == 0, stdout if stdout else stderr lines = stdout.splitlines() assert lines == [ "looking for '{}cppcheck.cfg'".format(exepath_sep), @@ -1959,7 +1959,7 @@ def test_checkers_report(tmpdir): f.write('x=1;') checkers_report = os.path.join(tmpdir, 'r.txt') exitcode, stdout, stderr = cppcheck(['--enable=all', '--checkers-report=' + checkers_report, test_file], remove_checkers_report=False) - assert exitcode == 0, stdout + assert exitcode == 0, stdout if stdout else stderr assert 'Active checkers:' in stderr assert '--checkers-report' not in stderr @@ -1973,7 +1973,7 @@ def test_checkers_report_misra_json(tmpdir): with open(misra_json, 'wt') as f: f.write('{"script":"misra.py"}') exitcode, stdout, stderr = cppcheck('--enable=style --addon=misra.json --xml-version=3 test.c'.split(), cwd=tmpdir) - assert exitcode == 0, stdout + assert exitcode == 0, stdout if stdout else stderr assert '' in stderr