Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Source full path #573

Open
nskmda opened this issue Dec 12, 2022 · 4 comments
Open

Source full path #573

nskmda opened this issue Dec 12, 2022 · 4 comments

Comments

@nskmda
Copy link

nskmda commented Dec 12, 2022

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?

@nskmda
Copy link
Author

nskmda commented Dec 12, 2022

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.

@plade
Copy link

plade commented May 18, 2023

I am also facing the same issue.

@nedbat
Copy link
Collaborator

nedbat commented May 18, 2023

Try adding this setting to your .coveragerc file (or other setting file): relative_files:

[run]
relative_files = true

@bravefencermusashi
Copy link

Try adding this setting to your .coveragerc file (or other setting file): relative_files:

[run]
relative_files = true

worked for me thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants