Skip to content

Commit c1da431

Browse files
authored
fixed #12308 - adjusted Python test files to match pytest conventions (danmar#5870)
This allows the tests to be picked up automatically instead of specifying patterns or filenames.
1 parent ac7a509 commit c1da431

22 files changed

+28
-20
lines changed

.github/workflows/CI-unixish.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -391,11 +391,11 @@ jobs:
391391
- name: Run test/cli
392392
run: |
393393
cd test/cli
394-
python3 -m pytest -Werror --strict-markers -vv test-*.py
394+
python3 -m pytest -Werror --strict-markers -vv
395395
cd ../../..
396396
ln -s cppcheck 'cpp check'
397397
cd 'cpp check/test/cli'
398-
python3 -m pytest -Werror --strict-markers -vv test-*.py
398+
python3 -m pytest -Werror --strict-markers -vv
399399
400400
- name: Run cfg tests
401401
if: matrix.os != 'ubuntu-22.04'

.github/workflows/CI-windows.yml

+1-7
Original file line numberDiff line numberDiff line change
@@ -168,13 +168,7 @@ jobs:
168168
copy .\bin\cppcheck.exe .\cppcheck.exe || exit /b !errorlevel!
169169
copy .\bin\cppcheck-core.dll .\cppcheck-core.dll || exit /b !errorlevel!
170170
cd test/cli || exit /b !errorlevel!
171-
:: python -m pytest -Werror --strict-markers -vv --suppress-no-test-exit-code test-clang-import.py || exit /b !errorlevel!
172-
python -m pytest -Werror --strict-markers -vv test-helloworld.py || exit /b !errorlevel!
173-
python -m pytest -Werror --strict-markers -vv test-inline-suppress.py || exit /b !errorlevel!
174-
python -m pytest -Werror --strict-markers -vv test-more-projects.py || exit /b !errorlevel!
175-
python -m pytest -Werror --strict-markers -vv test-other.py || exit /b !errorlevel!
176-
python -m pytest -Werror --strict-markers -vv test-proj2.py || exit /b !errorlevel!
177-
python -m pytest -Werror --strict-markers -vv test-suppress-syntaxError.py || exit /b !errorlevel!
171+
python -m pytest -Werror --strict-markers -vv || exit /b !errorlevel!
178172
179173
- name: Test addons
180174
if: matrix.config == 'release'

.github/workflows/asan.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ jobs:
9898
run: |
9999
pwd=$(pwd)
100100
cd test/cli
101-
TEST_CPPCHECK_EXE_LOOKUP_PATH="$pwd/cmake.output" python3 -m pytest -Werror --strict-markers -vv test-*.py
101+
TEST_CPPCHECK_EXE_LOOKUP_PATH="$pwd/cmake.output" python3 -m pytest -Werror --strict-markers -vv
102102
103103
- name: Generate dependencies
104104
if: false

.github/workflows/scriptcheck.yml

+5-5
Original file line numberDiff line numberDiff line change
@@ -143,14 +143,14 @@ jobs:
143143
- name: test addons
144144
if: matrix.python-version == '3.9' || matrix.python-version == '3.10'
145145
run: |
146-
python -m pytest --strict-markers -vv addons/test/test-*.py
146+
python -m pytest --strict-markers -vv addons/test
147147
env:
148148
PYTHONPATH: ./addons
149149

150150
- name: test addons
151151
if: matrix.python-version != '3.9' && matrix.python-version != '3.10'
152152
run: |
153-
python -m pytest -Werror --strict-markers -vv addons/test/test-*.py
153+
python -m pytest -Werror --strict-markers -vv addons/test
154154
env:
155155
PYTHONPATH: ./addons
156156

@@ -162,21 +162,21 @@ jobs:
162162
163163
- name: test reduce
164164
run: |
165-
python -m pytest -Werror --strict-markers -vv tools/test_reduce.py
165+
python -m pytest -Werror --strict-markers -vv tools/reduce_test.py
166166
env:
167167
PYTHONPATH: ./tools
168168

169169
- name: test donate_cpu_lib
170170
if: matrix.python-version != '2.7'
171171
run: |
172-
python -m pytest -Werror --strict-markers -vv tools/test_donate_cpu_lib.py
172+
python -m pytest -Werror --strict-markers -vv tools/donate_cpu_lib_test.py
173173
env:
174174
PYTHONPATH: ./tools
175175

176176
- name: test donate_cpu_server
177177
if: matrix.python-version != '2.7'
178178
run: |
179-
python -m pytest -Werror --strict-markers -vv tools/test_donate_cpu_server.py
179+
python -m pytest -Werror --strict-markers -vv tools/donate_cpu_server_test.py
180180
env:
181181
PYTHONPATH: ./tools
182182

.github/workflows/tsan.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ jobs:
9797
run: |
9898
pwd=$(pwd)
9999
cd test/cli
100-
TEST_CPPCHECK_EXE_LOOKUP_PATH="$pwd/cmake.output" python3 -m pytest -Werror --strict-markers -vv test-*.py
100+
TEST_CPPCHECK_EXE_LOOKUP_PATH="$pwd/cmake.output" python3 -m pytest -Werror --strict-markers -vv
101101
102102
- name: Generate dependencies
103103
if: false

.github/workflows/ubsan.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ jobs:
9797
run: |
9898
pwd=$(pwd)
9999
cd test/cli
100-
TEST_CPPCHECK_EXE_LOOKUP_PATH="$pwd/cmake.output" python3 -m pytest -Werror --strict-markers -vv test-*.py
100+
TEST_CPPCHECK_EXE_LOOKUP_PATH="$pwd/cmake.output" python3 -m pytest -Werror --strict-markers -vv
101101
102102
- name: Generate dependencies
103103
run: |
File renamed without changes.
File renamed without changes.

lib/importproject.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -455,9 +455,11 @@ bool ImportProject::importSln(std::istream &istr, const std::string &path, const
455455
if (pos1 == std::string::npos)
456456
continue;
457457
std::string vcxproj(line.substr(pos1+1, pos-pos1+7));
458+
vcxproj = Path::toNativeSeparators(std::move(vcxproj));
458459
if (!Path::isAbsolute(vcxproj))
459460
vcxproj = path + vcxproj;
460-
if (!importVcxproj(Path::fromNativeSeparators(vcxproj), variables, emptyString, fileFilters)) {
461+
vcxproj = Path::fromNativeSeparators(std::move(vcxproj));
462+
if (!importVcxproj(vcxproj, variables, emptyString, fileFilters)) {
461463
printError("failed to load '" + vcxproj + "' from Visual Studio solution");
462464
return false;
463465
}

test/cli/test-clang-import.py renamed to test/cli/clang-import_test.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import os
55
import re
66
import subprocess
7+
import sys
8+
79
import pytest
810
from testutils import cppcheck, assert_cppcheck
911

@@ -13,6 +15,11 @@
1315
pytest.skip("'clang' does not exist", allow_module_level=True)
1416

1517

18+
# the IDs differ with Visual Studio
19+
if sys.platform == 'win32':
20+
pytest.skip(allow_module_level=True)
21+
22+
1623
def get_debug_section(title, stdout):
1724
s = re.sub(r'0x[0-9a-fA-F]+', '0x12345678', stdout)
1825
s = re.sub(r'nestedIn: Struct', 'nestedIn: Class', s)
@@ -129,7 +136,7 @@ def test_log(tmpdir):
129136

130137
args = ['--clang', test_file]
131138
out_lines = [
132-
'Checking {} ...'.format(test_file),
139+
'Checking {} ...'.format(test_file).replace('\\', '/'),
133140
]
134141

135142
assert_cppcheck(args, ec_exp=0, err_exp=[], out_exp=out_lines)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

test/cli/test-project.py renamed to test/cli/project_test.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import pytest
44
import os
55
import json
6+
import sys
67
from testutils import cppcheck
78

89

@@ -49,6 +50,8 @@ def test_json_entry_file_not_found(tmpdir):
4950
]
5051

5152
expected = "'{}' from compilation database does not exist".format(os.path.join(tmpdir, "bug1.cpp"))
53+
if sys.platform == "win32":
54+
expected = expected.replace('\\', '/')
5255

5356
_test_project_error(tmpdir, "json", json.dumps(compilation_db), expected)
5457

@@ -117,7 +120,9 @@ def test_sln_project_file_not_found(tmpdir):
117120
"EndProject\r\n"
118121

119122
expected = "Visual Studio project file is not a valid XML - XML_ERROR_FILE_NOT_FOUND\n" \
120-
"cppcheck: error: failed to load '{}' from Visual Studio solution".format(os.path.join(tmpdir, "cli\\cli.vcxproj"))
123+
"cppcheck: error: failed to load '{}' from Visual Studio solution".format(os.path.join(tmpdir, "cli/cli.vcxproj"))
124+
if sys.platform == "win32":
125+
expected = expected.replace('\\', '/')
121126

122127
_test_project_error(tmpdir, "sln", content, expected)
123128

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)