Zim

Unable to run test case without Gtk

Bug #794476 reported by Jiří Janoušek
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Zim
In Progress
Undecided
Unassigned

Bug Description

Versions: Zim trunk r409, Debian 6, Python 2.6, python-unittest2 0.5.1-1

doublej@debian:~/trunk$ ./test.py
Traceback (most recent call last):
  File "./test.py", line 17, in <module>
    import tests
  File "/home/doublej/trunk/tests/__init__.py", line 29, in <module>
    from unittest import skip, skipIf, skipUnless
ImportError: cannot import name skip

After applying attached patch:
doublej@debian:~/trunk$ ./test.py
Traceback (most recent call last):
  File "./test.py", line 237, in <module>
    main()
  File "./test.py", line 88, in main
    suite = tests.load_tests(loader, None, None)
  File "/home/doublej/trunk/tests/__init__.py", line 81, in load_tests
    test = loader.loadTestsFromName(name)
  File "/usr/lib/pymodules/python2.6/unittest2/loader.py", line 120, in loadTestsFromName
    parent, obj = obj, getattr(obj, part)
AttributeError: 'module' object has no attribute 'applications'

Revision history for this message
Jiří Janoušek (fenryxo) wrote :
Revision history for this message
Jaap Karssenberg (jaap.karssenberg) wrote :

Will commit in rev410

Changed in zim:
status: New → Fix Committed
Revision history for this message
Jiří Janoušek (fenryxo) wrote :

My patch fixes only the first issue, the second one is still open. I'm sorry for confusion.

Changed in zim:
status: Fix Committed → In Progress
Revision history for this message
Jaap Karssenberg (jaap.karssenberg) wrote : Re: [Bug 794476] Re: Unable to run test case with Python 2.6

2nd one sounds like an import error in tests/applications.py. Try running it
with "PYTHONPATH='.' python ./tests/applications.py"

-- Jaap

Revision history for this message
Jiří Janoušek (fenryxo) wrote : Re: Unable to run test case with Python 2.6

$ PYTHONPATH='.' python ./tests/applications.py
Traceback (most recent call last):
  File "./tests/applications.py", line 8, in <module>
    import gtk
ImportError: No module named gtk

Yeah, tests/__init__.py seems to be unable to import this test case because of GTK import error. Is there any way to make tests/__init__.py skip test cases with import error? I guess I can run non-GTK tests manually one after one, but it is uncomfortable.

Revision history for this message
Jaap Karssenberg (jaap.karssenberg) wrote : Re: [Bug 794476] Re: Unable to run test case with Python 2.6

2011/6/9 Jiří Janoušek <email address hidden>

> $ PYTHONPATH='.' python ./tests/applications.py
> Traceback (most recent call last):
> File "./tests/applications.py", line 8, in <module>
> import gtk
> ImportError: No module named gtk
>
>
> Yeah, tests/__init__.py seems to be unable to import this test case because
> of GTK import error. Is there any way to make tests/__init__.py skip test
> cases with import error? I guess I can run non-GTK tests manually one after
> one, but it is uncomfortable.
>

Best way to handle it low level would be to wrap the imports in the test in
a try block and than put a decorator on the test class to skip if the import
failed. (See python 2.7 unittest documentation for facilities to skip
tests.) This would require tracking down all tests that directly or
indirectly require gtk. Bit of work, but a patch for this would be very
welcome.

Alternative would be to hard code a list of test modules that require gtk in
tests/__init__.py and have them removed from __all__ when gtk can not be
imported. Less clean solution but less work and still acceptable to me.
(Although I would like to see a warning when gtk tests are skipped - or
signal the test manager that the test is skipped.)

-- Jaap

Revision history for this message
Jaap Karssenberg (jaap.karssenberg) wrote :

On Tue, Jun 14, 2011 at 9:23 PM, Jaap Karssenberg <
<email address hidden>> wrote:

> 2011/6/9 Jiří Janoušek <email address hidden>
>
>> $ PYTHONPATH='.' python ./tests/applications.py
>> Traceback (most recent call last):
>> File "./tests/applications.py", line 8, in <module>
>> import gtk
>> ImportError: No module named gtk
>>
>>
>> Yeah, tests/__init__.py seems to be unable to import this test case
>> because of GTK import error. Is there any way to make tests/__init__.py
>> skip test cases with import error? I guess I can run non-GTK tests manually
>> one after one, but it is uncomfortable.
>>
>
> Best way to handle it low level would be to wrap the imports in the test in
> a try block and than put a decorator on the test class to skip if the import
> failed. (See python 2.7 unittest documentation for facilities to skip
> tests.) This would require tracking down all tests that directly or
> indirectly require gtk. Bit of work, but a patch for this would be very
> welcome.
>
> Alternative would be to hard code a list of test modules that require gtk
> in tests/__init__.py and have them removed from __all__ when gtk can not be
> imported. Less clean solution but less work and still acceptable to me.
> (Although I would like to see a warning when gtk tests are skipped - or
> signal the test manager that the test is skipped.)
>

P.S. maybe there is a nicer solution by wrapping the import of the test
modules in a try block and skipping all tests that fail.

Disadvantage of skipping per test module is that potentially we skip test
classes that could run without gtk but are in a module together with test
classes that do.

-- Jaap

summary: - Unable to run test case with Python 2.6
+ Unable to run test case without Gtk
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.