faq.rst 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. .. Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0
  2. .. For details: https://bitbucket.org/ned/coveragepy/src/default/NOTICE.txt
  3. .. _faq:
  4. ==================
  5. FAQ and other help
  6. ==================
  7. .. :history: 20090613T141800, brand new docs.
  8. .. :history: 20091005T073900, updated for 3.1.
  9. .. :history: 20091127T201500, updated for 3.2.
  10. .. :history: 20110605T175500, add the announcement mailing list.
  11. .. :history: 20121231T104700, Tweak the py3 text.
  12. Frequently asked questions
  13. --------------------------
  14. **Q: I use nose to run my tests, and its cover plugin doesn't let me create
  15. HTML or XML reports. What should I do?**
  16. First run your tests and collect coverage data with `nose`_ and its plugin.
  17. This will write coverage data into a .coverage file. Then run coverage.py from
  18. the :ref:`command line <cmd>` to create the reports you need from that data.
  19. .. _nose: http://nose.readthedocs.io
  20. **Q: Why do unexecutable lines show up as executed?**
  21. Usually this is because you've updated your code and run coverage.py on it
  22. again without erasing the old data. Coverage.py records line numbers executed,
  23. so the old data may have recorded a line number which has since moved, causing
  24. coverage.py to claim a line has been executed which cannot be.
  25. If you are using the ``-x`` command line action, it doesn't erase first by
  26. default. Switch to the ``coverage run`` command, or use the ``-e`` switch to
  27. erase all data before starting the next run.
  28. **Q: Why do the bodies of functions (or classes) show as executed, but the def
  29. lines do not?**
  30. This happens because coverage.py is started after the functions are defined.
  31. The definition lines are executed without coverage measurement, then
  32. coverage.py is started, then the function is called. This means the body is
  33. measured, but the definition of the function itself is not.
  34. To fix this, start coverage.py earlier. If you use the :ref:`command line
  35. <cmd>` to run your program with coverage.py, then your entire program will be
  36. monitored. If you are using the :ref:`API <api>`, you need to call
  37. coverage.start() before importing the modules that define your functions.
  38. **Q: Coverage.py is much slower than I remember, what's going on?**
  39. Make sure you are using the C trace function. Coverage.py provides two
  40. implementations of the trace function. The C implementation runs much faster.
  41. To see what you are running, use ``coverage debug sys``. The output contains
  42. details of the environment, including a line that says either ``tracer: CTracer``
  43. or ``tracer: PyTracer``. If it says ``PyTracer`` then you are using the
  44. slow Python implementation.
  45. Try re-installing coverage.py to see what happened and if you get the CTracer
  46. as you should.
  47. **Q: Does coverage.py work on Python 3.x?**
  48. Yes, Python 3 is fully supported.
  49. **Q: Isn't coverage testing the best thing ever?**
  50. It's good, but `it isn't perfect`__.
  51. __ http://nedbatchelder.com/blog/200710/flaws_in_coverage_measurement.html
  52. .. Other resources
  53. ---------------
  54. There are a number of projects that help integrate coverage.py into other
  55. systems:
  56. - `trialcoverage`_ is a plug-in for Twisted trial.
  57. .. _trialcoverage: http://pypi.python.org/pypi/trialcoverage
  58. - `pytest-coverage`_
  59. .. _pytest-coverage: http://pypi.python.org/pypi/pytest-coverage
  60. - `django-coverage`_ for use with Django.
  61. .. _django-coverage: http://pypi.python.org/pypi/django-coverage
  62. **Q: Where can I get more help with coverage.py?**
  63. You can discuss coverage.py or get help using it on the `Testing In Python`_
  64. mailing list.
  65. .. _Testing In Python: http://lists.idyll.org/listinfo/testing-in-python
  66. Bug reports are gladly accepted at the `Bitbucket issue tracker`_.
  67. .. _Bitbucket issue tracker: http://bitbucket.org/ned/coveragepy/issues
  68. Announcements of new coverage.py releases are sent to the
  69. `coveragepy-announce`_ mailing list.
  70. .. _coveragepy-announce: http://groups.google.com/group/coveragepy-announce
  71. `I can be reached`__ in a number of ways, I'm happy to answer questions about
  72. using coverage.py.
  73. __ http://nedbatchelder.com/site/aboutned.html
  74. History
  75. -------
  76. Coverage.py was originally written by `Gareth Rees`_.
  77. Since 2004, `Ned Batchelder`_ has extended and maintained it with the help of
  78. `many others`_. The :ref:`change history <changes>` has all the details.
  79. .. _Gareth Rees: http://garethrees.org/
  80. .. _Ned Batchelder: http://nedbatchelder.com
  81. .. _many others: http://bitbucket.org/ned/coveragepy/src/tip/AUTHORS.txt