Phoenix - pubsub unittests

3 views
Skip to first unread message

Werner

unread,
May 1, 2013, 1:24:24 PM5/1/13
to wxpyth...@googlegroups.com
Hi,

Created a test case which does the setup of pub and tears it down, split
the notify tests into individual files.

Changed all the tests to use it, now the only test failing if one runs
them all is "test_lib_pubsub_notify4", it runs successfully when run by
itself or with some of the others.

If some unittest and/or pubsub expert could shed a light on why this one
is still failing when one runs them all that would be great.

Werner
test_lib_pubsub_notify4.py
test_lib_pubsub_notify3.py
pubsubtests.patch

Robin Dunn

unread,
May 1, 2013, 8:23:20 PM5/1/13
to wxPyth...@googlegroups.com
I've run into that a few times too but figured it always had something
to do with having multiple wx.App objects (one for each test) being
created in the same process. I dealt with that by running each module in
a separate process and collecting the results from each in the parent
process.

I would guess that your case is probably something similar, where the
state of some pubsub thing in the process is not totally restored to a
pristine state before the next test case is run. Since the publisher
object is a singleton then when later tests do the setUp they are
probably actually getting the same object as the prior test. So perhaps
you should look into what it would take to completely reset pubsub in
tearDown.

BTW, could you remove the print statements from the tests? Not only
will they be syntax errors in Py3 without the ()'s but I don't think
they are a good idea in test cases except for temporary prints for
debugging the test itself. Otherwise the things that you would normally
print should be tested for success with test case asserts instead of
printing. That way if there is something wrong the testing framework
will be able to catch it without requiring human eyeballs watching the
test output results.

--
Robin Dunn
Software Craftsman
http://wxPython.org

werner

unread,
May 2, 2013, 3:27:52 AM5/2/13
to wxPyth...@googlegroups.com
On 02/05/2013 02:23, Robin Dunn wrote:
> Werner wrote:
>> Hi,
>>
>> Created a test case which does the setup of pub and tears it down, split
>> the notify tests into individual files.
>>
>> Changed all the tests to use it, now the only test failing if one runs
>> them all is "test_lib_pubsub_notify4", it runs successfully when run by
>> itself or with some of the others.
>>
>> If some unittest and/or pubsub expert could shed a light on why this one
>> is still failing when one runs them all that would be great.
>
> I've run into that a few times too but figured it always had something
> to do with having multiple wx.App objects (one for each test) being
> created in the same process. I dealt with that by running each module
> in a separate process and collecting the results from each in the
> parent process.
>
> I would guess that your case is probably something similar, where the
> state of some pubsub thing in the process is not totally restored to a
> pristine state before the next test case is run. Since the publisher
> object is a singleton then when later tests do the setUp they are
> probably actually getting the same object as the prior test. So
> perhaps you should look into what it would take to completely reset
> pubsub in tearDown.
I tried all kind of things, but this is really a bit over my head, will
have another look at it when I find some time and inspiration.
>
> BTW, could you remove the print statements from the tests?
Yes, they where just there to help narrow down the problem.

Werner

werner

unread,
May 2, 2013, 11:46:15 AM5/2/13
to wxPyth...@googlegroups.com
Hi Robin,

It is a bit of a brute force way of doing it as I couldn't find
another/cleaner way to totally get rid of 'pub' - see the tearDown method.

I think I have removed all "print" statements.

Werner
pubsubtests 2.patch

Robin Dunn

unread,
May 2, 2013, 8:03:30 PM5/2/13
to wxPyth...@googlegroups.com
werner wrote:
> Hi Robin,
>
> It is a bit of a brute force way of doing it as I couldn't find
> another/cleaner way to totally get rid of 'pub' - see the tearDown method.

I wonder if it would work to simply remove all the pubsub modules from
sys.modules, and then when it is imported again in the next setUp it
will have to do an actual import, executing the pusub init code, instead
of just using the already imported module. Something like this:

for name in sys.modules.keys():
if 'pubsub' in name:
del sys.modules[name]


>
> I think I have removed all "print" statements.

Thanks.

werner

unread,
May 3, 2013, 2:52:17 AM5/3/13
to wxPyth...@googlegroups.com
On 03/05/2013 02:03, Robin Dunn wrote:
> for name in sys.modules.keys():
> if 'pubsub' in name:
> del sys.modules[name]
That gave me the exception below.

But just doing this:
if 'wx.lib.pubsub.pub' in sys.modules.keys():
del sys.modules['wx.lib.pubsub.pub']

seems to be enough to force pub to import from "scratch".

Werner

TypeError: coercing to Unicode: need string or buffer, NoneType found
File "C:\Program Files (x86)\Wing IDE
4.1\src\testing\runners\run_unittests_xml.py", line 149, in RunInSingleDir
unittest.TestProgram(argv=argv, module=None, testRunner=runner)
File "c:\Python27\Lib\unittest\main.py", line 95, in __init__
self.runTests()
File "c:\Python27\Lib\unittest\main.py", line 229, in runTests
self.result = testRunner.run(self.test)
File "C:\Program Files (x86)\Wing IDE
4.1\src\testing\runners\wingtest_common.py", line 573, in run
test(self.result)
File "c:\Python27\Lib\unittest\suite.py", line 70, in __call__
return self.run(*args, **kwds)
File "c:\Python27\Lib\unittest\suite.py", line 108, in run
test(result)
File "c:\Python27\Lib\unittest\suite.py", line 70, in __call__
return self.run(*args, **kwds)
File "c:\Python27\Lib\unittest\suite.py", line 108, in run
test(result)
File "c:\Python27\Lib\unittest\suite.py", line 70, in __call__
return self.run(*args, **kwds)
File "c:\Python27\Lib\unittest\suite.py", line 108, in run
test(result)
File "c:\Python27\Lib\unittest\case.py", line 391, in __call__
return self.run(*args, **kwds)
File "c:\Python27\Lib\unittest\case.py", line 302, in run
result.startTest(self)
File "C:\Program Files (x86)\Wing IDE
4.1\src\testing\runners\wingtest_common.py", line 509, in startTest
lineno=lineno)
File "C:\Program Files (x86)\Wing IDE
4.1\src\testing\runners\wingtest_common.py", line 179, in _start_test
% (xml_escape(name), xml_escape(filename)))
File "C:\Program Files (x86)\Wing IDE
4.1\src\testing\runners\wingtest_common.py", line 55, in xml_escape
utext = _unicode(text, 'utf_8', 'replace')

pubsubtests 3.patch

werner

unread,
May 3, 2013, 3:05:59 AM5/3/13
to wxPyth...@googlegroups.com
Hi Robin,

Cried victory to soon, when back in to clean up the doc string and when
I run it again I got failures again.

For the moment I leave the code to delete the test topic in there.

Have to try to make progress on my other problem, will get back to this
hopefully next week.

Werner
pubsubtests 4.patch

werner

unread,
May 4, 2013, 8:55:13 AM5/4/13
to wxPyth...@googlegroups.com
Hi Robin,

Just noticed that I had forgotten to send you these two tests.

Werner

test_lib_pubsub_notify2_2.py
test_lib_pubsub_notify2_1.py
Reply all
Reply to author
Forward
0 new messages