1

The title pretty much says it. I'm having problems connected to the change in the unittest python from python 2.5 to 2.7. When I run my test script with python

python _tester.py

it works fine. But when I try to use the coverage tool

coverage erase; coverage run _tester.py; coverage html -d html_cov_report

it crashes saying that assertRaisesRegexp is not an attribute of my subclass of TestCase. I discovered that this was because the coverage tool was using python 2.5 and unittest.TestCase.assertRaisesRegexp does not exist in 2.5.

Anyway, can somebody tell me how to change the python used by coverage?

EDIT: The egg for coverage is in /Library/Python/2.5/site-packages. Does that matter?

oz123
  • 27,559
  • 27
  • 125
  • 187
Harrison
  • 830
  • 1
  • 15
  • 28

2 Answers2

1

I'm thinking of 4 options (with order of what should be done IMHO):

  1. You can install coverage under python2.7 and not python 2.5.
  2. I think this should be fixed if you run the coverage script using python 2.7: /path/to/python2.7 /path/to/coverage ..., assuming that python2.5 is the default one.
  3. use unittest2.
  4. you can change the default python to python 2.7 as i believe coverage script shebang should be /usr/bin/env python
mouad
  • 67,571
  • 18
  • 114
  • 106
  • I used easy_install to install coverage (I'm on a mac). Is there a way I can specify which version of python to install it for, using easy_install? – Harrison Jul 12 '12 at 21:27
  • what's your default python ? ``python -V``. – mouad Jul 12 '12 at 21:29
  • Ok my **first** guess was wrong ;-), can you do ``which coverage`` and check the shebang it should be ``/usr/bin/env python`` and check if it's pointing to python 2.7, b/c if it's pointing to python2.5 then there is your problem; you will have to remove the current ``coverage`` package and install it again and check that it's using python 2.7, hope i get it right this time. – mouad Jul 12 '12 at 21:43
  • Aha! The python the shebang points to is version 2.5.4. Forgot about the "which" command. Thanks! – Harrison Jul 12 '12 at 21:46
  • @Harrison: Glad you found your solution :) – mouad Jul 12 '12 at 21:56
0

The coverage script should have a shebang that can be changed to the right version of python.

Edit: If you installed it in python 2.5, it is probably easiest to switch to installing using python 2.7.

Jerome
  • 1,429
  • 11
  • 13
  • There is at least 36 files in the coverage dir. I looked in the ones that looked like likely "run" modules (__init__.py, exec_file.py,...) but didn't see any shebangs at the top. Should I add one? – Harrison Jul 12 '12 at 21:25
  • Please don't try to edit the coverage.py files. Just re-install it into the Python installation you want. – Ned Batchelder Jul 13 '12 at 12:38