How can we measure coverage of python executables, e.g., files that dont have .py extension. I am using coverage.py python tool
I am using python coverage.py tool to find the code coverage. But its not giving coverage report for python programs that dont have .py extension. Please help!
See also questions close to this topic
How to download and silent install .exe file with given URL using Python 3
I have a URL which is a download link to a software .exe file (Dynamic but the url function fetches it correctly each time). The intended operation is to use Python 3 to download the said file and then do a silent installation.
url = get_internal_link(check_if_inserted) url = str(url) httpurl = re.sub("ftp://","https://",url) downloadurl = httpurl.replace("'","").replace(',','').replace(":2100/FTP Folders/Software","") downloadurl = downloadurl.strip("(").strip(")")
The pandas value error still shows, but the code is totally correct and it loads normally the visualization
I really wanted to use
pd.options.mode.chained_assignment = None, but I wanted a code clean of error.
My start code:
import datetime import altair as alt import operator import pandas as pd s = pd.read_csv('../../data/aparecida-small-sample.csv', parse_dates=['date']) city = s[s['city'] == 'Aparecida']
Based on @dpkandy's code:
city['total_cases'] = city['totalCases'] city['total_deaths'] = city['totalDeaths'] city['total_recovered'] = city['totalRecovered'] tempTotalCases = city[['date','total_cases']] tempTotalCases["title"] = "Confirmed" tempTotalDeaths = city[['date','total_deaths']] tempTotalDeaths["title"] = "Deaths" tempTotalRecovered = city[['date','total_recovered']] tempTotalRecovered["title"] = "Recovered" temp = tempTotalCases.append(tempTotalDeaths) temp = temp.append(tempTotalRecovered) totalCases = alt.Chart(temp).mark_bar().encode(alt.X('date:T', title = None), alt.Y('total_cases:Q', title = None)) totalDeaths = alt.Chart(temp).mark_bar().encode(alt.X('date:T', title = None), alt.Y('total_deaths:Q', title = None)) totalRecovered = alt.Chart(temp).mark_bar().encode(alt.X('date:T', title = None), alt.Y('total_recovered:Q', title = None)) (totalCases + totalRecovered + totalDeaths).encode(color=alt.Color('title', scale = alt.Scale(range = ['#106466','#DC143C','#87C232']), legend = alt.Legend(title="Legend colour"))).properties(title = "Cumulative number of confirmed cases, deaths and recovered", width = 800)
This code works perfectly and loaded normally the visualization image, but it still shows the pandas error, asking to try to set
.loc[row_indexer,col_indexer] = value instead, then I was reading the documentation "Returning a view versus a copy" whose linked cited and also tried this code, but it still shows the same error. Here is the code with
# 1st attempt tempTotalCases.loc["title"] = "Confirmed" tempTotalDeaths.loc["title"] = "Deaths" tempTotalRecovered.loc["title"] = "Recovered" # 2nd attempt tempTotalCases["title"].loc = "Confirmed" tempTotalDeaths["title"].loc = "Deaths" tempTotalRecovered["title"].loc = "Recovered"
Here is the error message:
<ipython-input-6-f16b79f95b84>:6: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy tempTotalCases["title"] = "Confirmed" <ipython-input-6-f16b79f95b84>:9: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy tempTotalDeaths["title"] = "Deaths" <ipython-input-6-f16b79f95b84>:12: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy tempTotalRecovered["title"] = "Recovered"
Jupyter and Pandas version:
$ jupyter --version jupyter core : 4.7.1 jupyter-notebook : 6.3.0 qtconsole : 5.0.3 ipython : 7.22.0 ipykernel : 5.5.3 jupyter client : 6.1.12 jupyter lab : 3.1.0a3 nbconvert : 6.0.7 ipywidgets : 7.6.3 nbformat : 5.1.3 traitlets : 5.0.5 $ pip show pandas Name: pandas Version: 1.2.4 Summary: Powerful data structures for data analysis, time series, and statistics Home-page: https://pandas.pydata.org Author: None Author-email: None License: BSD Location: /home/gus/PUC/.env/lib/python3.9/site-packages Requires: pytz, python-dateutil, numpy Required-by: ipychart, altair
SQLAlchemy Core GROUP BY calculated field
I literally can't find this in the documentation anywhere nor can I find a related question (my guess is because I don't know how to ask it) so I'm really hoping this is low hanging fruit.
I'm trying to rewrite this in SQLAlchemy Core:
SELECT A.COLUMN1, CASE WHEN A.COLUMN2 = "IN" THEN "HELLO", WHEN A.COLUMN2 = "OUT" THEN "WORLD" ELSE "!" END AS MYCASE, sum(A.COLUMN3) FROM MY_FUN_TABLE A GROUP BY A.COLUMN1, MYCASE;
This is all super simple except for the
MYCASEpart. How do I put the calculated field
sql = select(a.c.COLUMN1, case([(a.c.COLUMN2 == "IN", "HELLO"), (a.c.COLUMN2 == "OUT", "WORLD")], else_="!").label("MYCASE"), func.sum(a.c.COLUMN3) ) sql = sql.groupby(a.c.COLUMN1, **?????**)
Thank you all in advance for your thoughts.
python.__version__ == 3.9.4,
sqlalchemy.__version__ == 1.4.7
SonarQube test coverage .NET 5
I want to show test coverage for my .NET 5 unit tests in my local SonarQube instance (on Windows).
dotnet sonarscanner begin /k:"MyProject" /d:sonar.host.url="http://localhost:9000" /d:sonar.login="<token>" /d:sonar.cs.opencover.reportsPaths="**\TestResults\*\*.xml" dotnet build dotnet test --no-build --collect:"XPlat Code Coverage" dotnet sonarscanner end /d:sonar.login="<token>"
dotnet testcommand generates the coverage reports as
coverage.cobertura.xmlfiles in the
In the logs I can see the following warning:
WARN: Could not import coverage report '<MyTestProject>\TestResults\a4af5812-7f80-469b-8876-3ea0c7c4c98d\coverage.cobertura.xml' because 'Missing root element <CoverageSession> in C:\Users\<Path>\TestResults\a4af5812-7f80-469b-8876-3ea0c7c4c98d\coverage.cobertura.xml at line 2'. Troubleshooting guide: https://community.sonarsource.com/t/37151
Following the link from the warning message, I can see that only Visual Studio Code Coverage, dotCover and OpenCover/Coverlet are supported. As far as I can tell from their GitHub page, is OpenCover/Coverlet is "XPlat Code Coverage".
In my test projects the
coverlet.collectorNuGet package v 3.0.3 is installed.
What am I missing?
I found this related question: SonarQube: Unable to import test coverage but it doesn't help me because I can't use dotCover.
Select suite of tests for coverage with pytest
I'm running a set of tests with
pytestand want also to measure its coverage with the
I have some decorators in my code, dividing the tests in several suites using something like:
@pytest.mark.firstgroup def test_myfirsttest(): assert True is True @pytest.mark.secondgroup def test_mysecondtest(): assert False is False
I need to find something like:
coverage run --suite=firstgroup -m pytest
So that in this case only the first test, since it's in the correct suite, will be used to test coverage.
The suites work correctly when I use directly
pytestbut I don't know how to use them in
Is there any way to configure
coverageto achieve this?
How to run JaCoCo in Android Studio for test coverage?
I like to use JaCoCo inside of Android Studio 4.2 RC1 instead of the default configured IntelliJ IDEA code coverage option. Therefore, I changed the relevant option in the run configuration:
debugbuild type I have
testCoverageEnabled trueconfigured (if needed at all?).
Once I run the "Run test with coverage" button in the IDE then the following failure shows up:
Task :app:testDebugUnitTest FAILED FAILURE: Build failed with an exception.
- Where: Initialization script '/tmp/ijresolvers.gradle' line: 152
- What went wrong: Execution failed for task ':app:testDebugUnitTest'.
- IntelliJ IDEA code coverage documentation
- The Developers' Bakery - #09 - JaCoCo with Evgeny Mandrikov
- JaCoCo with IntelliJ
- How can i run Jacoco in android studio for code coverage
- Jacoco Code Coverage in android studio
- YouTrack IDEA-252731: JaCoCo coverage runner fails with Kotlin multi-platform project
coverage cannot find modules in my project
I am trying to use coverage from the terminal (as I am using the community version of pycharm, which doesn't have support for coverage). However, I always get the same error:
ModuleNotFoundError: No module named 'src'The package structure of my project is very simple: it has 2 packages, src and test, and inside the test package is another package called unit, wherer I keep my unit tests.
This is the code that I have trying to run with coverage.
import unittest from src.interpolacion import interpolacion class DummyTest(unittest.TestCase): def test_nothing(self): self.assertTrue(True) if __name__ == '__main__': unittest.main()
Please notice how src.interpolacion.interpolacion is not even used and, regardless, it fails with this error:
====================================================================== ERROR: DummyTest (unittest.loader._FailedTest) ---------------------------------------------------------------------- ImportError: Failed to import test module: DummyTest Traceback (most recent call last): File "C:\Users\jose.m.ramirez.leon\AppData\Local\Programs\Python\Python38\lib\unittest\loader.py", line 154, in loadTestsFromName module = __import__(module_name) File "C:\Users\jose.m.ramirez.leon\PycharmProjects\dummyPythonProject\test\unit\DummyTest.py", line 2, in <module> from src.interpolacion import interpolacion ModuleNotFoundError: No module named 'src'
I am going mad with this. Could anyone please help me regain my sanity?
Correct way to measure code coverage on files that are executed on a program that will never end
I'm having problems using
coveragewhen some of the code can't be directly reached by pytest.
Specifically, I have a program that runs several waitress processes to serve requests. In my tests, for which I'm running coverage with
coverage run -m pytestI'm getting valid results, but for the tests where I just call an endpoint, the code that processes the request is not being marked as covered.
For all the other tests, the code is marked as covered/uncovered as expected.
I tried to run my script using coverage directly. That is
coverage run myprogram.pyinstead of
python myprogram.py. However, this didn't work since the
.coveragefile is only written at the end, and this program is prepared to run until we need to kill it.
Is there a way to include the code of these endpoints into the coverage results? The decorators and lines defining the function on those files is being marked as covered, and also the lines executed as a result of non-endpoint tests