coverage.py

Running tests from coverage.py vs running coverage from test runner

不羁岁月 提交于 2019-12-21 05:52:02
问题 During the Coverage.py with Ned Batchelder python&testing podcast, Brian and Ned briefly discussed that, if you need to run tests with coverage, it is preferred to run tests from coverage.py executing the coverage run as opposed to invoking a test runner with coverage. Why is that and what is the difference? To put some context into this: currently I'm using nose test runner and execute the tests with the help of nosetests command-line tool with --with-coverage option: $ nosetests --with

coverage.py does not cover script if py.test executes it from another directory

我是研究僧i 提交于 2019-12-18 11:07:55
问题 I got a python script which takes command line arguments, working with some files. I'm writing succeeding tests with py.test putting this script through its paces, executing it with subprocess.call . Now I want to analyze code coverage with coverage.py . Coverage, when used via the pytest-cov plugin (which has subprocess-handling built-in), does not see/cover my script when it is called from a temporary testing directory created with py.test 's tmpdir fixture. Coverage does see my script when

How to properly use coverage.py in Python?

☆樱花仙子☆ 提交于 2019-12-18 10:48:26
问题 I've just started using Coverage.py module and so decided to make a simple test to check how it works. Sample.py def sum(num1, num2): return num1 + num2 def sum_only_positive(num1, num2): if num1 > 0 and num2 > 0: return num1 + num2 else: return None test.py from sample import sum, sum_only_positive def test_sum(): assert sum(5, 5) == 10 def test_sum_positive_ok(): assert sum_only_positive(2, 2) == 4 def test_sum_positive_fail(): assert sum_only_positive(-1, 2) is None As you see, all my code

Code Coverage not working with PyDev

情到浓时终转凉″ 提交于 2019-12-13 19:15:11
问题 First, sorry for asking again. I found some posts on this topic, but none of the recommendations worked for me. The outcome is well known: PyDev always reports "File has no statistics". In a previous installation (Linux and Windows) I saw this working as described in the PyDev homepage. This is my installation: Ubuntu 15.10 Eclipse Mars.1 PyDev 4.4.0.201510052309 python 3.4 coverage 4.0.3 (found in /usr/local/lib/python3.4/dist-packages) In Eclipse/PyDev the Coverage view is shown, the basic

Can't get Coverage to work in PyDev, “File has no statistics”

你说的曾经没有我的故事 提交于 2019-12-13 16:15:32
问题 I can't get Coverage to work with PyDev. Every file I run shows up with: "File has no statistics." I'm following the instructions by checking 'Enable code coverage for new launches', and dragging the folder to analyze over to the Code Coverage window. I've successfully installed coverage. After that, I refreshed my Python Interpreter settings, where the coverage folder shows up automatically. I've also tried to add the coverage folder to my project's External Libraries. Didn't work either...

Test Coverage for Flask application doesnt work

£可爱£侵袭症+ 提交于 2019-12-10 20:40:01
问题 Hi want to test the "delete route" in my flask application in terminal I can see that the test is past and it said "test_user_delete (test_app.LayoutTestCase) ... ok" But when I open the cover page it still with red color which means doesn't cover it wold you please someone explain to me why and where I am doing wrong? app.layout.view.py test.py e1 = Users(name='admine2', email='admine2@gmail.com', age=25) e2 = Users(name='teste2', email='teste2@gmail.com', age=27) db.session.add_all([e1, e2]

How to add variable error to regex fuzzy search. Python

泄露秘密 提交于 2019-12-10 19:37:55
问题 import regex,re sequence = 'aaaaaaaaaaaabbbbbbbbbbbbcccccccccccc' #being searched query = 'aaabbbbbbbbbbbbccc' #100% coverage query_1 = 'aaaabbbbbbbbcbbbcccc' #95% coverage query_2 = 'aaabbbbcbbbbbcbccc' #90% coverage threshold = .95 error = len(query_1) - (len(query_1)*threshold) #for query_1 errors must be <= 1 print regex.search(query_1 + '{e<={}}'.format(error),sequence).group(0) Im trying to add additional parameters to a regex search so it only works if a certain percentage of the query

How to generate coverage report for http based integration tests?

烈酒焚心 提交于 2019-12-10 13:25:59
问题 I am writing integration tests for a project in which I am making HTTP calls and testing whether they were successful or not. Since I am not importing any module and not calling functions directly coverage.py report for this is 0%. I want to know how can I generate coverage report for such integration HTTP request tests? 回答1: The recipe is pretty much this: Ensure the backend starts in code coverage mode Run the tests Ensure the backend coverage is written to file Read the coverage from file

Python Code Coverage and Multiprocessing

独自空忆成欢 提交于 2019-12-10 00:52:25
问题 I use coveralls in combination with coverage.py to track python code coverage of my testing scripts. I use the following commands: coverage run --parallel-mode --source=mysource --omit=*/stuff/idont/need.py ./mysource/tests/run_all_tests.py coverage combine coveralls --verbose This works quite nicely with the exception of multiprocessing. Code executed by worker pools or child processes is not tracked. Is there a possibility to also track multiprocessing code? Any particular option I am

Reporting cumulative coverage across multiple Python versions

筅森魡賤 提交于 2019-12-09 15:54:09
问题 I have code that runs conditionally depending on the current version of Python, because I'm supporting 2.6, 2.7, and 3.3 from the same package. I currently generate a coverage report like this, using the default version of Python: coverage run --source mypackage setup.py test coverage report -m coverage html This is useful but not ideal, as it only reports coverage on Python 2.7. Instead, I would like to generate a cumulative report of the test coverage across 2.6, 2.7, and 3.2. How do I