Source full path
Team,
I'm trying to set up Python build in a project which is 'governed' by Gradle. I'm also trying to use Gradle/Maven-conventional source path for Python files (src/main/python, src/test/python).
In general, everything works fine and as expected with one caveat (for me, specifically).
I'm using pytest with pytest.ini where I set pytest-cov configuration with the following:
[pytest]
norecursedirs = .gradle/** gradle/** build/** out/** **/src/main/python/**
python_files = *_spec.py
python_functions = feature_*
pythonpath = src/main/python
addopts = --cov=src/main/python --cov-config=.coveragerc --cov-report xml:build/test-results/python.xml --cov-report html:build/reports/tests/python src/test/python
and corresponding .coveragerc:
[run]
omit = **/test/**
source = src/test/python
The problem I'm having is the path to the source files in the python.xml test coverage report.
It seems to prefix the src/main/python with the output of the pwd command and I'm effectively getting stuff like
<sources>
<source>/home/jenkins/workspace/pipeline-name-here/application/src/main/python</source>
</sources>
where /home/jenkins/workspace/pipeline-name-here/application/ is that annoying prefix I'm need to get rid of.
My Gradle folder structure (w/service folders omitted) is like
|-- Git-name-of-the-project
|--- ansible
|--- ansible files
|--- application
|--- <temp build-related folders>
|--- src
|--- main
|--- python
|--- python-file.py
|--- gradlew <etc>
|--- .coveragerc
|--- pytest.ini
Any suggestions?
Oh, sorry, forgot to mention how I'm running the whole thing via Gradle Python plugin.
The command I'm executing is [supposedly] python -m pytest which is run in the application folder being the current working directory.
I am also facing the same issue.
Try adding this setting to your .coveragerc file (or other setting file): relative_files:
[run]
relative_files = true
Try adding this setting to your .coveragerc file (or other setting file): relative_files:
[run] relative_files = true
worked for me thanks