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
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 validates coverage reports by checking:
- File existence - Verifies that the file exists at the specified path
- File readability - Ensures the file is readable and accessible
- File format - Validates that coverage reports are in valid Cobertura XML format
- Root element - Checks that XML root element is
<coverage>(expected Cobertura format)
Successful validation:
Coverage Report Paths: coverage.xml
✓ Coverage report is valid Cobertura XML: 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
Before running a full analysis, verify that coverage reports are correctly configured:
pysonar \
--token "myToken" \
--project-key "my:project" \
--sonar-python-coverage-report-paths "coverage/cobertura.xml" \
--dry-runVerify that all configuration sources are properly resolved:
# Set configuration in multiple places
export SONAR_HOST_URL="https://sonarqube.example.com"
pysonar \
--token "myToken" \
--project-key "my:project" \
--dry-runThis 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:
# First, validate the configuration
pysonar \
--token "myToken" \
--project-key "my:project" \
--sonar-python-coverage-report-paths "coverage/cobertura.xml" \
--dry-run
# If successful, run the full analysis
pysonar \
--token "myToken" \
--project-key "my:project" \
--sonar-python-coverage-report-paths "coverage/cobertura.xml"When onboarding a new project, use dry-run mode to validate the setup before the first full analysis:
# Create your configuration in pyproject.toml or via CLI
# Then validate it:
pysonar --dry-run -vError 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 - Ensure the process running the scanner has read access
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
- Try generating the coverage report again
- Check the coverage tool documentation for 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
- Check that your coverage tool is configured to output Cobertura XML
- For Python projects using coverage.py, use:
coverage xml
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"