From 1a5ee37c52e25c98010066b451e796aed042c71b Mon Sep 17 00:00:00 2001 From: shenxianpeng Date: Fri, 16 Aug 2024 16:18:26 +0300 Subject: [PATCH] add fixture --- tests/test_clang_tidy.py | 10 ++++++++-- tests/test_util.py | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/tests/test_clang_tidy.py b/tests/test_clang_tidy.py index 4259a9b..10252ca 100644 --- a/tests/test_clang_tidy.py +++ b/tests/test_clang_tidy.py @@ -5,15 +5,21 @@ from cpp_linter_hooks.clang_tidy import run_clang_tidy +@pytest.fixture(scope='function') +def generate_compilation_database(): + # Generate compilation database + subprocess.run(['mkdir', '-p', 'build', '&&', 'cmake', '-Bbuild', 'testing/'], shell=True) + + @pytest.mark.parametrize( ('args', 'expected_retval'), ( (['--checks="boost-*"'], 1), (['--checks="boost-*"', '--version=16'], 1), ), ) -def test_run_clang_tidy_valid(args, expected_retval, tmp_path): - subprocess.run(['mkdir', '-p', 'build', '&&', 'cmake', '-Bbuild', 'testing/'], shell=True) +def test_run_clang_tidy_valid(args, expected_retval, tmp_path, generate_compilation_database): # copy test file to tmp_path to prevent modifying repo data + generate_compilation_database test_file = tmp_path / "main.c" test_file.write_bytes(Path("testing/main.c").read_bytes()) ret, output = run_clang_tidy(args + [str(test_file)]) diff --git a/tests/test_util.py b/tests/test_util.py index ad21156..2901083 100644 --- a/tests/test_util.py +++ b/tests/test_util.py @@ -33,7 +33,7 @@ def test_ensure_installed(tool, version, tmp_path, monkeypatch, caplog): # first run should install assert caplog.record_tuples[0][2] == f"Checking for {tool}, version {bin_version}" if run == 0: - # FIXME + # FIXME # assert caplog.record_tuples[1][2] == f"Installing {tool}, version {bin_version}" assert caplog.record_tuples[1][2] == f"{tool}, version {bin_version} is already installed" # second run should just confirm it's already installed