The Pysonar scanner supports a dry-run mode that helps you troubleshoot configuration issues without connecting to a SonarQube server or submitting analysis results. This is particularly useful when:
- Setting up new projects
- Adjusting coverage report paths
- Validating configuration properties
- Debugging analysis failures related to configuration
Use dry-run mode to verify your configuration is correct before running a full analysis. This is especially useful when setting up new projects or making configuration changes:
pysonar \
--token "myToken" \
--project-key "my:project" \
--sonar-python-coverage-report-paths "coverage/cobertura.xml" \
--dry-runOr with minimal configuration:
pysonar --dry-run -vThis validates all configuration sources (pyproject.toml, environment variables, CLI arguments) and checks that coverage report paths are valid before submitting any analysis. This also helps ensure that environment variables, CLI arguments, and configuration files are being read correctly.
If an analysis fails, use dry-run mode to quickly identify configuration issues without waiting for a full analysis. This is especially useful for catching problems with configuration files, environment variables, or required properties before attempting a full analysis.
To run the scanner in dry-run mode, add the --dry-run flag:
pysonar --token "myToken" --project-key "my:project" --dry-runAlternatively, use the property format:
pysonar -Dsonar.scanner.dryRun=trueOr set it as an environment variable:
export SONAR_SCANNER_DRY_RUN=true
pysonarWhen dry-run mode is enabled, the scanner:
- Skips SonarQube server validation - No connection attempt to the SonarQube server is made
- Skips analysis submission - No data is sent to or modified on the server
- Resolves configuration - Loads configuration from all sources (CLI, environment variables, pyproject.toml, etc.)
- Reports resolved configuration - Displays the detected settings including:
- Project key and name
- Organization (if applicable)
- Detected main source directories
- Detected test source directories
- Configured coverage report paths
- Server URL (if configured)
- Validates coverage reports - Checks coverage report paths and formats with clear error reporting
In dry-run mode, the scanner outputs a configuration summary. Example:
================================================================================
DRY RUN MODE - Configuration Report
================================================================================
Project Configuration:
Project Key: my:project
Project Name: My Project
Organization: my-org
Server Configuration:
Host Url: https://sonarcloud.io
Source Configuration:
Sources: src
Tests: tests
Coverage Configuration:
Coverage Report Paths: coverage/cobertura.xml
================================================================================
DRY RUN MODE - Validation Results
================================================================================
✓ Configuration validation PASSED
================================================================================
The scanner performs basic validation of coverage reports by checking:
- File existence - Verifies that the file exists at the specified path
- File readability - Ensures the file is readable and accessible
- XML format - Validates that the file can be parsed as valid XML
- Root element - Checks that XML root element is
<coverage>(expected Cobertura format)
Note: This is a basic sanity check and does not perform full schema validation of the Cobertura format.
Successful validation:
Coverage Report Paths: coverage.xml
✓ Coverage report check passed: coverage.xml
Missing file error:
✗ Configuration validation FAILED with the following issues:
✗ Coverage report not found: coverage.xml (resolved to /project/coverage.xml)
Invalid format error:
✗ Configuration validation FAILED with the following issues:
✗ Coverage report is not valid XML (Cobertura format): coverage.xml (Parse error: XML not well-formed (invalid token))
- 0: Configuration validation passed, no errors found
- 1: Configuration validation failed, errors were found
Error message:
Coverage report not found: coverage.xml (resolved to /project/coverage.xml)
Solution:
- Verify the file path is correct relative to the project base directory
- Check that the file actually exists:
ls -la /project/coverage.xml - Use absolute paths if relative paths are not working
- Ensure the scanner is run from the correct directory
Error message:
Coverage report is not readable (permission denied): coverage.xml
Solution:
- Check file permissions:
ls -l coverage.xml - Make the file readable:
chmod 644 coverage.xml
Error message:
Coverage report is not valid XML (Cobertura format): coverage.xml (Parse error: XML not well-formed (invalid token))
Solution:
- Verify the coverage report was generated correctly with your coverage tool
- Check the coverage tool documentation for the proper output format
Warning message:
Coverage report root element is 'report', expected 'coverage' (Cobertura format)
Solution:
- The coverage report may not be in Cobertura XML format
- For Python projects using coverage.py, generate the report with:
coverage xml - Check that your coverage tool is configured to output Cobertura XML format
Dry-run mode is particularly useful in CI/CD pipelines to fail fast on configuration issues:
- name: Validate configuration
run: |
pysonar \
--token ${{ secrets.SONAR_TOKEN }} \
--project-key ${{ env.SONAR_PROJECT_KEY }} \
--sonar-python-coverage-report-paths "coverage/cobertura.xml" \
--dry-run
- name: Run analysis
run: |
pysonar \
--token ${{ secrets.SONAR_TOKEN }} \
--project-key ${{ env.SONAR_PROJECT_KEY }} \
--sonar-python-coverage-report-paths "coverage/cobertura.xml"validate_config:
script:
- pysonar
--token $SONAR_TOKEN
--project-key $SONAR_PROJECT_KEY
--sonar-python-coverage-report-paths "coverage/cobertura.xml"
--dry-run
analyze:
script:
- pysonar
--token $SONAR_TOKEN
--project-key $SONAR_PROJECT_KEY
--sonar-python-coverage-report-paths "coverage/cobertura.xml"