beeware / cricket

A GUI tool for running Python test suites.
BSD 3-Clause "New" or "Revised" License
213 stars 69 forks source link

Vanilla cricket install fails under Windows + Python 2.6.6 #24

Closed lensvol closed 11 years ago

lensvol commented 11 years ago

At the moment cricket implicitly relies on ttk and unittest from 2.7, which causes install from PyPi to fail:

Traceback (most recent call last): ... File "D:\Projects\env\kinder\Lib\site-packages\cricket\djangomain.py", line 4, in from cricket.main import main as cricket_main File "D:\Projects\env\kinder\Lib\site-packages\cricket\main.py", line 11, in from cricket.view import ( File "D:\Projects\env\kinder\Lib\site-packages\cricket\view.py", line 8, in from ttk import * ImportError: No module named ttk

After that it fails because of changed module structure in unittest from 2.7:

File "D:\Projects\env\kinder\Lib\site-packages\cricket\djangomain.py", line 4, in from cricket.main import main as cricket_main File "D:\Projects\env\kinder\Lib\site-packages\cricket\main.py", line 11, in from cricket.view import ( File "D:\Projects\env\kinder\Lib\site-packages\cricket\view.py", line 16, in from cricket.executor import Executor File "D:\Projects\env\kinder\Lib\site-packages\cricket\executor.py", line 13, in from cricket.pipes import PipedTestResult, PipedTestRunner File "D:\Projects\env\kinder\Lib\site-packages\cricket\pipes.py", line 40, in class PipedTestResult(unittest.result.TestResult): AttributeError: 'module' object has no attribute 'result'

This because in old unittest TestResult> was import from unittest directly, while in >2.7 it needs to be imported from unittest.result.

While ImportError with ttk can be fixed relatively straightforward with adding pyttk to REQUIREMENTS, I'm not sure how to deal with unittest situation.

Possible solution seems to be falling back to unittest2:

import sys
if sys.version_info < (2, 7):
     try:
          import unittest2 as unittest
     except ImportError:
          print "cricket relies on changes introduced into unittest in Python 2.7.\n"\
                 "You can install backported version from PyPi:\n\tpip install unittest2"
          sys.exit(0)

But it seems somewhat hacky. :(

freakboy3742 commented 11 years ago

It's hacky, but it's what needs to be done :-) There's already a couple of shims like this in cricket, and Django has them by the bucketload.

The error message isn't needed though; setup.py alters the required_packages based on Python version, so we can force the install of unittest2 if we're working with Python2.6.

lensvol commented 11 years ago

Completely forgot about "required_packages", thank you :)

Btw, what is more appropriate way to contribute bugfixes here: start an issue with proposed solution or submit pull requests with ready code? I've got couple more patches coming and not sure how to proceed.

freakboy3742 commented 11 years ago

Depends how big the issue/patch is. If it's a relatively minor thing -- e.g., adding an import shim for Python 2.6 compatibility -- then going straight to a pull request is fine. If there's likely to be some discussion needed on the right technical approach, then lodging a ticket first is probably the best idea.

freakboy3742 commented 11 years ago

Regarding the pyttk dependency - you mentioned on a different thread that you were testing on Windows 7 -- I'm testing on windows 7 as well, and pyttk wasn't needed.

In response to a recent report from a friend, I added some advice to the docs/README regarding getting going under Windows -- if you're using a virtualenv, you need to set an extra environment variable for Cricket to work, or you'll get "Can't find TTK library" errors. Is this the problem you encountered? Does it go away if you follow the (new) advice in the README?

freakboy3742 commented 11 years ago

Ah - and now I've seen your updated PR - it's about ttk specifically, not tkinter. My mistake.