Code Coverage and Unit Testing of Python Code
Asked Answered
P

7

28

I have already visited Preferred Python unit-testing framework. I am not just looking at Python Unit Testing Framework, but also code coverage with respect to unit tests. So far I have only come across coverage.py. Is there any better option?

An interesting option for me is to integrate cpython, unit testing of Python code and code coverage of Python code with Visual Studio 2008 through plugins (something similar to IronPython Studio). What can be done to achieve this? I look forward to suggestions.

Pagas answered 7/11, 2008 at 14:19 Comment(3)
Maybe you could define "better". What do you want to do that coverage.py doesn't do? How do you need it to be better?Monia
I was referring to Limitations (section 4 of nedbatchelder.com/code/modules/rees-coverage.html) when I mentioned "better".Pagas
I'd add that integration of coverage.py with IDEs (Eclipse, in my particular case) would be great.Jaymie
J
4

PyDev seems to allow code coverage from within Eclipse.

I've yet to find how to integrate that with my own (rather complex) build process, so I use Ned Batchelder's coverage.py at the command line.

Jaymie answered 27/11, 2008 at 18:50 Comment(1)
I suggest a visit to #2263277Pagas
B
5

We use this Django coverage integration, but instead of using the default coverage.py reporting, we generate some simple HTML: Colorize Python source using the built-in tokenizer.

Brasil answered 7/11, 2008 at 19:10 Comment(0)
J
4

PyDev seems to allow code coverage from within Eclipse.

I've yet to find how to integrate that with my own (rather complex) build process, so I use Ned Batchelder's coverage.py at the command line.

Jaymie answered 27/11, 2008 at 18:50 Comment(1)
I suggest a visit to #2263277Pagas
C
2

There is also figleaf which I think is based on Ned Batchelder's coverage.py. We use nose as the driver for the testing. It all works pretty well. We write our unit tests using the built-in unittest and doctest modules.

Calices answered 7/11, 2008 at 16:22 Comment(0)
G
2

NetBeans' new Python support has tightly integrated code coverage support - more info here.

Giveandtake answered 17/12, 2008 at 3:58 Comment(0)
K
1

If you want interactive code coverage, where you can see your coverage stats change in real time, take a look at Python Coverage Validator.

Kisangani answered 24/4, 2010 at 19:46 Comment(0)
B
0

Testoob has a neat "--coverage" command-line option to generate a coverage report.

Binnie answered 13/11, 2008 at 23:12 Comment(3)
Orip, which branch of Testoob has the --coverage option? I've 1.13 release currently installed, but it doesn't seem to have that option there. Cheers HDive
Ah, ignore that. Wasn't reading the docs correctly. For other interested parties, use the following syntax: testoob --coverage=normal test_file.py types of coverage are silent, slim, normal, massive, or xmlDive
@howard: glad you like it :) There's a new version with some coverage improvements coming out soon.Binnie
T
0

PyCharm has a feature to see coverage: https://www.jetbrains.com/help/pycharm/coverage-settings.html:

enter image description here

To run with coverage:

enter image description here

Result:

File coverage:

enter image description here

Branch coverage:

enter image description here

Tested with PyCharm 2023.3.1.

Thorsten answered 11/7, 2024 at 4:21 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.