单元测试框架:在新的流程运行测试

我编程谁使用单元测试框架的GUI应用程序。 该应用程序显示了树视图中的所有单元测试。 如果你点击了一个单元测试的名字,程序会运行这个测试,并显示结果。 有用!

但现在我想在一个新的进程中运行的每个测试用例。 我创建了一个“工作线”(与模块线程),但此线程也在同一个进程中运行。

该模块“多”是解决方案,但我有我的执行问题。 我把我在自己的功能“测试执行代码”,并尝试:

item = self.GetSelection() name = self.GetItemText(item) p = multiprocessing.Process(target=ExecuteTest, args=(name, item)) p.daemon = True p.start()

但后来我得到了错误。

Traceback (most recent call last): File "C:\a\b\c\hhh\a.py", line 577, in OnLeftDClick p.start() File "C:\Python26\lib\multiprocessing\process.py", line 104, in start self._popen = Popen(self) File "C:\Python26\lib\multiprocessing\forking.py", line 239, in __init__ dump(process_obj, to_child, HIGHEST_PROTOCOL) File "C:\Python26\lib\multiprocessing\forking.py", line 162, in dump ForkingPickler(file, protocol).dump(obj) File "C:\Python26\lib\pickle.py", line 224, in dump self.save(obj) File "C:\Python26\lib\pickle.py", line 331, in save self.save_reduce(obj=obj, *rv) File "C:\Python26\lib\pickle.py", line 419, in save_reduce save(state) File "C:\Python26\lib\pickle.py", line 286, in save f(self, obj) # Call unbound method with explicit self File "C:\Python26\lib\pickle.py", line 649, in save_dict self._batch_setitems(obj.iteritems()) File "C:\Python26\lib\pickle.py", line 681, in _batch_setitems save(v) File "C:\Python26\lib\pickle.py", line 286, in save f(self, obj) # Call unbound method with explicit self File "C:\Python26\lib\pickle.py", line 548, in save_tuple save(element) File "C:\Python26\lib\pickle.py", line 331, in save self.save_reduce(obj=obj, *rv) File "C:\Python26\lib\pickle.py", line 419, in save_reduce save(state) File "C:\Python26\lib\pickle.py", line 286, in save f(self, obj) # Call unbound method with explicit self File "C:\Python26\lib\pickle.py", line 649, in save_dict self._batch_setitems(obj.iteritems()) File "C:\Python26\lib\pickle.py", line 686, in _batch_setitems save(v) File "C:\Python26\lib\pickle.py", line 331, in save self.save_reduce(obj=obj, *rv) File "C:\Python26\lib\pickle.py", line 396, in save_reduce save(cls) File "C:\Python26\lib\pickle.py", line 286, in save f(self, obj) # Call unbound method with explicit self File "C:\Python26\lib\pickle.py", line 748, in save_global (obj, module, name)) pickle.PicklingError: Can't pickle <type 'PySwigObject'>: it's not found as __builtin__.PySwigObject Traceback (most recent call last): File "<string>", line 1, in <module> File "C:\Python26\lib\multiprocessing\forking.py", line 342, in main self = load(from_parent) File "C:\Python26\lib\pickle.py", line 1370, in load return Unpickler(file).load() File "C:\Python26\lib\pickle.py", line 858, in load dispatch[key](self) File "C:\Python26\lib\pickle.py", line 880, in load_eof raise EOFError EOFError

没有任何人有任何想法?

--------------解决方案-------------

很显然,你想“泡菜”的东西是不是可拾取(似乎是一个WX对象)。 尝试按照参数仅“简单”的对象使用(即没有内部图形对象),并应更好的工作。 您还可以看看到蟒蛇鼻子UNITEST库,可以自动运行multiprocesses测试。

产卵用fork一个子进程。 这将需要一些工作,从你,但会奏效。

作为注:multiprocessnig模块使用叉子实现。



更新:你的代码仔细观察后,似乎item viariable不与pickle(就是一个字?)。 我不认为你需要它,你可以用更简单的东西(价值或某种)替换它。

我建议你创建一个运行测试单独的脚本,那么你可以使用subprocess模块调用该脚本,给它的测试运行的名称。

奖金是,那么你可以使用相同的脚本持续集成服务器,每晚构建,或者说不需要GUI等间歇式工艺。

分类:蟒蛇 时间:2015-03-15 人气:0
本文关键词: 单元测试,蟒蛇,多
分享到:

相关文章

Copyright (C) 55228885.com, All Rights Reserved.

55228885 版权所有 京ICP备15002868号

processed in 0.685 (s). 10 q(s)