Exclusions issues

I’m trying to exclude tests folder from being scanned. My directory structures are as follows:

/
/source
/build
/tests/
/tests/others/

I’ve tried:
sonar.exclusions=<exclusion pattern>
sonar.coverage.exclusions=<exclusion pattern>
sonar.test.exclusions=<exclusion pattern>

Where <exclusion pattern> has the one of the following patterns:
tests/**
tests/*.py
tests/**/*
**/tests/**
**/tests/**/*

I see the following messages from the scan (using the -X debug mode):
INFO: Excluded sources: tests/**
INFO: Excluded tests: tests/**
INFO: Excluded sources for coverage: tests/**

(excluded pattern would match the <exclusion pattern>)

No matter which pattern I use, I still see this message:

INFO: 0 files ignored because of inclusion/exclusion patterns

I am getting thousands of WARNING messages from the scans for files in the tests folder.

Other variables that I have set includes:
sonar.projectBaseDir=<project root>
sonar.sources=<project root>/source
sonar.python.python.xunit.reportPath=<project root>/report.xml
sonar.python.coverage.reportPaths=<project root>/coverage.xml

I am using SonarCloud, scanning python (3.8) code. I’ve tried modifying the settings in both CLI and in the SonarCloud gui.

How do I exclude my tests folders from being scanned/tested?

Thank you.

Hey there.

What are the warning messages you’re getting? Issues in SonarCloud, or warnings in the analysis logs?

It’s related to this thread:

The xxx.xxx are for files in the tests folder.
tests.test_1
tests.test_2
etc.

This is part of a Jenkins job. After the code is built, it gets unit tested (using tox), then it is scanned by sonar. The analysis logs spams 8000+ WARNING messages as I believe they are correspond to the unit tested. I have other jobs that is also having this issue.

Are any of my exclusion patterns correct? If so, the sonar-scanner should not scan the tests directory, or is there something else I am missing?

Thanks

Any ideals?

Anyone?

Hi @Colin

Would you be able to assist me on this?

I would like to be able to exclude the /tests directory from being scanned. I’ve tried multiple exclusion patterns but none of them seem to work.

Thanks

Hey there.

This warning:

The resource for ‘xxx.xxx’ is not found, drilling down to the details of this test won’t be possible

Is not actually related to the analysis of test files (you can see if they are being included in analysis via the Code tab of your project), but it actually has to do with the import of test execution reports.

I would suggest following this advice:

If any paths in the report are invalid, set sonar.python.xunit.skipDetails=true to collect only project-level details.

1 Like

Awesome!

That did the trick! Thanks!

Cheers!

Sure thing. And sorry for the delay.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.