Python unit-testing: view annotated coverage report in terminal - python

I'm using Python's unittest for testing, and I know I can view per-source-file annotated coverage report in browser by exporting it to HTML files with:
coverage run -m unittest *_test.py
coverage html
But I want to view this in Linux/Unix command line: view a given source file, with covered lines marked with green, and missed lines marked with red.
I tested several terminal web browsers (w3m, links, elinks, links2) and none of them can display these html files in a readable manner.
Maybe I'm missing something, because it looks like a very obvious feature to have in "coverage" or "green" or other testing tools, but I can't find anything!

There isn't a way to get colored source file reports in the terminal. You can use coverage annotate to get annotated source files currently.
Perhaps it makes sense now to get rid of the old-style annotate, and replace it with a rich terminal report.

Related

Using the Coverage Python API to get coverage results after a run

I want to generate a Markdown report after a coverage run, so I tried to use the Python API, particularly the CoverageData class. I can get the lines covered with CoverageData.lines(<file>), however I don't see how to get the percentage. Any pointers?
You should use the coverage json command to get a JSON data file, then process it however you like. It will be easier than using the API.

Deep customize Allure report pages

I am looking at the docs, and I can't get any progress in customizing the allure report.
I do generate the report using the python version of the allure tool. the output is nice, but it is the default one, and I can't find a way to make changes to the standard UI.
I did find some examples online, where the reports are quite different from the default that I get, and I can't figure out exactly how did they customize the reports. The manual online does specify how to add various elements to the report, like steps, attachments, but not much about how do you modify the pages, generated from the XML output file, by the allure tool.
Is this even possible or is a limitation of the allure python tool?
Due to the lack of progress, I am seriously thinking to look elsewhere and find a different reporting framework; although I like Allure since it integrate into py.test seamlessly with few decorators (and most of the frameworks that I did find, look like they were made in the 90s and mostly for Java).
In allure 2 was planned pluginization for change default view of results. Now it is in beta, but still hasn't any docs about api. Maybe some features that you want is ready, otherwise you can contribuite to project. Please, explain what kind of features you need here or here and we try to help you.

Pygments to latex better formatting for py code

I am trying to include python code in my lyx document by inserting a file. I began by trying to use listings but this was causing code to overflow pages.
Now I'm using pygments setting it up as described in this tutorial, http://wiki.lyx.org/Examples/IncludeExternalProgramListingUsingPygments. This appears to work fairly well but the code highlighting is off. for instance def and elif keywords are not highlighted and docstrings do not highlight if they are split over multiple lines.
I have tried changing the style to a few different built in ones but this hasn't worked.
Has anyone got a/ knows of a good way to highlight python code in the same way as idle does.
Thanks.
You should check out package called minted, although I don't know how well it works together with Lyx. But in regular latex file you can just do:
\usepackage{minted}
...
\inputminted[]{python}{python_file.py}

PyCharm and filters for external tools

I'm trying out PyCharm for Django development and so far am extremely happy. My team strictly follows PEP8 formatting and we use the pep8 command line program to check to make sure our code conforms.
I've configured an external tool command to run pep8 and it works good. I see the capability to create filters that will cause the output to be parsed into something PyCharm can use. I've read the docs and searched Google but can't find an example to make this work. Docs are http://www.jetbrains.com/pycharm/webhelp/add-filter-dialog.html
I'm using PyCharm 1.2 and the output filter I'm using looks like this:
$FILE_PATH$:$LINE$:$COLUMN:.*
Example output looks like this:
/home/matt/.../settings.py:13:30: E261 at least two spaces before inline comment
/home/matt/.../settings.py:20:80: E501 line too long (126 characters)
What would be even more awesome is if this could be run each time the file is saved.
You've missed a $ off the end of COLUMN. I followed your steps and I have it working perfectly. Your filter should be:
$FILE_PATH$:$LINE$:$COLUMN$:.*
Update: To have it work for PyCharm 1.5 use:
$FILE_PATH$\:$LINE$\:$COLUMN$\:.*
PyCharm expects full file path for the links to work, not just the name.

python nose framework: A plugin to display results in a human friendly format

Any format which is targeted for humans (.html, .doc, whatever) would be good. I cannot find any plugin that provides it
All I found was XUNIT or XML output..
I don't know of a stand-alone visualization tool, but Hudson can graph your test and coverage results. If there's a failure, it will list the problems on a web page with hyperlinks to each individual test result.
This blog post explains the setup: http://heisel.org/blog/2009/11/21/django-hudson/. There's a screenshot at the bottom that shows what's possible. It's geared toward django, but the idea is applicable to any python app.
A continuous integration server gives you many benefits beyond just graphing your test results. Hudson can automatically checkout your code after a subversion commit, run all your tests, email you if there's a failure, etc..
http://hudson-ci.org/
Nose has an html output module! (the --cover-html option). See here : http://somethingaboutorange.com/mrl/projects/nose/0.11.1/plugins/cover.html
nosetest provide a way to dump result to xunit-xml format. use options below -
--with-xunit --xunit-file <file.xml>
once you have results, you can use xslt to convert your runs to xhtml.
I tried https://github.com/mungayree/nosetest-xunit-xslt
it displays result of your runs.

Categories

Resources