Skip to content

Commit 176edd8

Browse files
Further fixes
1 parent 3e0b7bf commit 176edd8

4 files changed

Lines changed: 20 additions & 1 deletion

File tree

CLI_ARGS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
| `--sonar-python-analysis-parallel`, `--no-sonar-python-analysis-parallel`, `--analysis-in-parallel`, `--no-analysis-in-parallel`, `-Dsonar.python.analysis.parallel` | When set to False the analysis will be single threaded |
6969
| `--sonar-python-analysis-threads`, `--nr-analysis-threads`, `-Dsonar.python.analysis.threads` | Set the number of threads to use during analysis. This property is ignored if --sonar-python-analysis-parallel is set to False |
7070
| `--sonar-python-skip-unchanged`, `--no-sonar-python-skip-unchanged` | Override the SonarQube configuration of skipping or not the analysis of unchanged Python files |
71+
| `--sonar-python-test-file-heuristic-disabled`, `--no-sonar-python-test-file-heuristic-disabled` | Disable the sonar-python heuristic that silences issues on test-like files when sonar.tests is not set. Use this to analyse all files as main code regardless of their path. |
7172
| `--sonar-qualitygate-timeout`, `-Dsonar.qualitygate.timeout` | The number of seconds that the scanner should wait for a report to be processed |
7273
| `--sonar-qualitygate-wait`, `--no-sonar-qualitygate-wait` | Forces the analysis step to poll the server instance and wait for the Quality Gate status |
7374
| `--sonar-scanner-api-url`, `-Dsonar.scanner.apiUrl` | Base URL for all REST-compliant API calls, https://api.sonarcloud.io for example |
@@ -99,6 +100,7 @@
99100
| `--sonar-working-directory`, `-Dsonar.working.directory` | Path to the working directory used by the Sonar scanner during a project analysis to store temporary data |
100101
| `--toml-path` | Path to the pyproject.toml file or to the folder containing it. If not provided, it will look in the SONAR_PROJECT_BASE_DIR |
101102
| `-Dsonar.python.skipUnchanged` | Equivalent to --sonar-python-skip-unchanged |
103+
| `-Dsonar.python.testFileHeuristic.disabled` | Equivalent to --sonar-python-test-file-heuristic-disabled |
102104
| `-Dsonar.python.xunit.skipDetails` | Equivalent to -Dsonar.python.xunit.skipDetails |
103105
| `-Dsonar.qualitygate.wait` | Equivalent to --sonar-qualitygate-wait |
104106
| `-Dsonar.scm.exclusions.disabled` | Equivalent to --sonar-scm-exclusions-disabled |

src/pysonar_scanner/configuration/cli.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,17 @@ def __create_parser(cls):
363363
action=argparse.BooleanOptionalAction,
364364
help="Override the SonarQube configuration of skipping or not the analysis of unchanged Python files",
365365
)
366+
scanner_behavior_group.add_argument(
367+
"--sonar-python-test-file-heuristic-disabled",
368+
action=argparse.BooleanOptionalAction,
369+
help="Disable the sonar-python heuristic that silences issues on test-like files when sonar.tests is not set. "
370+
"Use this to analyse all files as main code regardless of their path.",
371+
)
372+
scanner_behavior_group.add_argument(
373+
"-Dsonar.python.testFileHeuristic.disabled",
374+
type=bool,
375+
help="Equivalent to --sonar-python-test-file-heuristic-disabled",
376+
)
366377
scanner_behavior_group.add_argument(
367378
"--dry-run",
368379
action=argparse.BooleanOptionalAction,

src/pysonar_scanner/configuration/configuration_loader.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def load() -> dict[Key, Any]:
7777
# Auto-detect sonar.tests only when the user has not set it in any higher-priority source
7878
# and has not explicitly disabled the sonar-python test file heuristic. When the heuristic
7979
# is disabled the intent is to analyse all files as main code with no test classification.
80-
heuristic_disabled = resolved_properties.get(SONAR_PYTHON_TEST_FILE_HEURISTIC_DISABLED, "").lower() == "true"
80+
heuristic_disabled = str(resolved_properties.get(SONAR_PYTHON_TEST_FILE_HEURISTIC_DISABLED, "")).lower() == "true"
8181
if SONAR_TESTS not in resolved_properties and not heuristic_disabled:
8282
inferred_props, disable_heuristic = test_paths_loader.load(base_dir)
8383
resolved_properties.update(inferred_props)

src/pysonar_scanner/configuration/properties.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,12 @@ def env_variable_name(self) -> str:
505505
default_value=None,
506506
cli_getter=lambda args: args.sonar_python_skip_unchanged or getattr(args, "Dsonar.python.skipUnchanged")
507507
),
508+
Property(
509+
name=SONAR_PYTHON_TEST_FILE_HEURISTIC_DISABLED,
510+
default_value=None,
511+
cli_getter=lambda args: args.sonar_python_test_file_heuristic_disabled
512+
or getattr(args, "Dsonar.python.testFileHeuristic.disabled"),
513+
),
508514
Property(
509515
name=SONAR_PYTHON_XUNIT_REPORT_PATH,
510516
default_value=None,

0 commit comments

Comments
 (0)