我正在尝试从SonarQube分析中排除测试。 我在詹金斯的声纳扫描仪中设置了以下内容:
sonar.sources=.
sonar.exclusions=manage.py, rone/wsgi.py, rone/settings/**, rone/utils/**, rone/service/tests/**
我有报道和xunit报告。
sonar.python.coverage.reportPaths=./rone_env/rone_service/coverage.xml
sonar.python.xunit.reportPath=./rone_env/rone_service/xunittest.xml
问题是我没有分析xunittest结果,因为它没有找到测试文件来获取详细信息。
因此,我添加了以下内容以包括xunittest结果的测试文件。
sonar.tests=./rone/service/tests
现在,我得到了很好的xunittest报告,但是我也对不需要的代码气味和重复进行了测试分析。
我尝试了使用排除和包含的不同组合
sonar.test.inclusions
sonar.test.exclusions
sonar.coverage.exclusions
sonar.cpd.exclusions
没有运气。
SonarQube版本是6.7.6版
SonarScanner版本是3.3.0.1492
编辑1。
这里是SonarScanner的完整配置。 tests文件夹中有13个测试文件,所有这些文件都包含在代码分析中。
# must be unique in a given SonarQube instance
sonar.projectKey=RoneService
# this is the name and version displayed in the SonarQube UI. Was mandatory prior to SonarQube 6.1.
sonar.projectName=rone_service
sonar.projectVersion=1.0
# Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows.
# This property is optional if sonar.modules is set.
sonar.sources=.
sonar.tests=./rone/service/tests
sonar.exclusions=manage.py, rone/wsgi.py, rone/settings/**, rone/utils/**, rone/service/tests/**
sonar.language=py
sonar.projectBaseDir=./rone_env/rone_service
# Encoding of the source code. Default is default system encoding
# sonar.sourceEncoding=UTF-8
# Python Coverage Results Import
sonar.python.coverage.reportPaths=./rone_env/rone_service/coverage.xml
# Python Unit Tests Execution Reports Import
sonar.python.xunit.reportPath=./rone_env/rone_service/xunittest.xml
# Import Pylint Issues Report
sonar.python.pylint.reportPath=./rone_env/rone_service/pylint-report.txt
# Add this line to Additional arguments field to get more verbose debug logs from SonarScanner
# -Dsonar.verbose=true -X
编辑2。
这是来自索引文件的调试日志
10:41:19.397 INFO: Language is forced to py
10:41:19.402 DEBUG: Initializers :
10:41:19.403 INFO: Index files
10:41:19.406 INFO: Excluded sources:
10:41:19.406 INFO: manage.py
10:41:19.406 INFO: rone/wsgi.py
10:41:19.406 INFO: rone/settings/**
10:41:19.406 INFO: rone/utils/**
10:41:19.406 INFO: rone/service/tests/**
10:41:19.423 DEBUG: 'rone/__init__.py' indexed with language 'py'
10:41:19.428 DEBUG: 'rone/service/__init__.py' indexed with language 'py'
10:41:19.429 DEBUG: 'rone/service/models.py' indexed with language 'py'
10:41:19.431 DEBUG: 'rone/service/urls.py' indexed with language 'py'
10:41:19.432 DEBUG: 'rone/service/serializers/keytask.py' indexed with language 'py'
10:41:19.433 DEBUG: 'rone/service/serializers/rulegroup.py' indexed with language 'py'
10:41:19.433 DEBUG: 'rone/service/views/__init__.py' indexed with language 'py'
10:41:19.435 DEBUG: 'rone/service/views/keytask.py' indexed with language 'py'
10:41:19.436 DEBUG: 'rone/service/views/rulegroup.py' indexed with language 'py'
10:41:19.437 DEBUG: 'rone/service/apps.py' indexed with language 'py'
10:41:19.440 DEBUG: 'rone/urls.py' indexed with language 'py'
10:41:19.446 DEBUG: 'rone/service/tests/tests_rulegroup_create.py' indexed as test with language 'py'
10:41:19.446 DEBUG: 'rone/service/tests/__init__.py' indexed as test with language 'py'
10:41:19.448 DEBUG: 'rone/service/tests/tests_rulegroup_filerules_update.py' indexed as test with language 'py'
10:41:19.449 DEBUG: 'rone/service/tests/tests_applicationfilerule_create.py' indexed as test with language 'py'
10:41:19.450 DEBUG: 'rone/service/tests/tests_rulegroup_delete.py' indexed as test with language 'py'
10:41:19.451 DEBUG: 'rone/service/tests/tests_keytask.py' indexed as test with language 'py'
10:41:19.451 DEBUG: 'rone/service/tests/tests_rulegroup_list.py' indexed as test with language 'py'
10:41:19.452 DEBUG: 'rone/service/tests/tests_applicationfilerule_list.py' indexed as test with language 'py'
10:41:19.453 DEBUG: 'rone/service/tests/tests_rulegroup_filerules_update_property.py' indexed as test with language 'py'
10:41:19.455 DEBUG: 'rone/service/tests/local_test_mixin.py' indexed as test with language 'py'
10:41:19.456 DEBUG: 'rone/service/tests/tests_applicationfilerule_delete.py' indexed as test with language 'py'
10:41:19.456 INFO: 22 files indexed
10:41:19.457 INFO: 18 files ignored because of inclusion/exclusion patterns
编辑3.-解决方案 问题是pylint报告没有适当的排除。 因此,在导入Pylint / lint时,Coverage和UnitTest报告。检查那些不会导入任何不需要的结果。学过的知识。 :D