我有装饰器传递变量'insurance_mode'的问题.我会通过以下装饰器声明来做到这一点:
@execute_complete_reservation(True)
def test_booking_gta_object(self):
self.test_select_gta_object()
Run Code Online (Sandbox Code Playgroud)
但不幸的是,这种说法不起作用.也许有更好的方法可以解决这个问题.
def execute_complete_reservation(test_case,insurance_mode):
def inner_function(self,*args,**kwargs):
self.test_create_qsf_query()
test_case(self,*args,**kwargs)
self.test_select_room_option()
if insurance_mode:
self.test_accept_insurance_crosseling()
else:
self.test_decline_insurance_crosseling()
self.test_configure_pax_details()
self.test_configure_payer_details
return inner_function
Run Code Online (Sandbox Code Playgroud) 从列表中提取项目并将它们作为参数传递给函数调用的简单方法是什么,如下例所示?
例:
def add(a,b,c,d,e):
print(a,b,c,d,e)
x=(1,2,3,4,5)
add(magic_function(x))
Run Code Online (Sandbox Code Playgroud) 什么是Enum在Python 3.4中扩展类型的最佳实践,是否有可能这样做?
例如:
from enum import Enum
class EventStatus(Enum):
success = 0
failure = 1
class BookingStatus(EventStatus):
duplicate = 2
unknown = 3
Traceback (most recent call last):
...
TypeError: Cannot extend enumerations
Run Code Online (Sandbox Code Playgroud)
目前没有可能的方法来创建一个带有成员的基本枚举类,并在其他枚举类中使用它(如上例所示).有没有其他方法来实现Python枚举的继承?
我如何获得当前运行的测试用例名称,而在testsuite集合中有16个测试用例.测试按顺序执行(按testSuite集合添加测试的顺序).当我将所有测试添加到testSuite集合时,我可以预览此对象但是如何在测试运行时获得当前正在执行的测试.也许某些变量包含这些信息?
例:
def suite():
testSuite= unittest.TestSuite()
testSuite.addTest(FlightsTestCases('test_sel__reservation_one_way_wizzair_transfer'))
testSuite.addTest(FlightsTestCases('test_sel_reservation_one_way_wizzair_transfer'))
testSuite.addTest(FlightsTestCases('test_sel_reservation_round_wizzair_transfer'))
testSuite.addTest(FlightsTestCases('test_sel_reservation_one_way_tair_transfer'))
testSuite.addTest(FlightsTestCases('test_sel_reservation_round_tair_transfer'))
testSuite.addTest(FlightsTestCases('test_sel_reservation_one_way_wizzair_credit_card'))
testSuite.addTest(FlightsTestCases('test_sel_reservation_one_way_tair_credit_card'))
testSuite.addTest(FlightsTestCases('test_sel_reservation_round_wizzair_transfer'))
testSuite.addTest(FlightsTestCases('test_sel_reservation_one_way_wizzair_transfer'))
testSuite.addTest(FlightsTestCases('test_sel_reservation_one_way_easyjet_transfer'))
testSuite.addTest(FlightsTestCases('test_sel_reservation_one_way_ryanair_transfer'))
testSuite.addTest(FlightsTestCases('test_sel_reservation_round_ryanair_credit_card'))
testSuite.addTest(FlightsTestCases('test_sel_reservation_one_way_tair_duplicated'))
testSuite.addTest(FlightsTestCases('test_reservation_wrong_card_lowcost'))
testSuite.addTest(FlightsTestCases('test_sel_reservation_one_way_tair_credit_card'))
testSuite.addTest(FlightsTestCases('test_sel_reservation_one_way_tair_wrong_credit_card'))
return testSuite
if __name__ == "__main__":
result = unittest.TextTestRunner(verbosity=2).run(suite())
sys.exit(not result.wasSuccessful())
Run Code Online (Sandbox Code Playgroud)
使用Selenium-RC框架执行测试.
我尝试使用drawtext参数在FFmpeg上添加简单文本.每次我要这样做,都会返回错误:
无法从文件'arial.ttf'加载字体:无法打开资源
为了表明字体的位置,我使用了以下方法:
ffmpeg -i C:\Test\rec\vid_1321909320.avi -vf drawtext=fontfile=arial.ttf:text=test -sameq vid_1321909320.flv
ffmpeg -i C:\Test\rec\vid_1321909320.avi -vf drawtext=fontfile=C:\Windows\Fonts\arial.ttf:text=test -sameq vid_1321909320.flv
Run Code Online (Sandbox Code Playgroud)
一切都失败了.有没有人有使用ffmpeg添加文本的经验?
FFMPEG version: N-34549-g13b7781 build on Nov 6 2011
Run Code Online (Sandbox Code Playgroud) 我遇到了一个我无法解决的问题,它与多处理相关并在装饰器中使用它.
当我run_in_parallels使用多处理调用方法时,我收到错误:
Can't pickle <function run_testcase at 0x00000000027789C8>: it's not found as __main__.run_testcase
调用发生在装饰器内部,然后是上述问题.在run_in_parallels没有装饰器的情况下调用相同的方法时,所有工作正常.
这个问题的原因是什么?
file: w_PythonHelper.py
desc:函数'run_in_parallel'用于同时运行多个进程.第一种方法,即结束操作将停止其他操作.
from multiprocessing import Process,Event
class ExtProcess(Process):
def __init__(self, event,*args,**kwargs):
self.event=event
Process.__init__(self,*args,**kwargs)
def run(self):
Process.run(self)
self.event.set()
class PythonHelper(object):
@staticmethod
def run_in_parallel(*functions):
event=Event()
processes=dict()
for function in functions:
fname=function[0]
try:fargs=function[1]
except:fargs=list()
try:fproc=function[2]
except:fproc=1
for i in range(fproc):
process=ExtProcess(event,target=fname,args=fargs)
process.start()
processes[process.pid]=process
event.wait()
for process in processes.values():
process.terminate()
for process in processes.values():
process.join()
Run Code Online (Sandbox Code Playgroud)
file: w_Recorder.py
desc:函数'capture'用于获取截图
from PIL import ImageGrab …Run Code Online (Sandbox Code Playgroud) 我刚刚注意到multiprocessingLinux上进程终止(来自库)方法的问题.我有应用程序使用multiprocessing库,但...当我terminate在Windows上调用函数一切都很好,另一方面Linux失败了这个解决方案.作为过程杀戮的替代,我被迫使用
os.system('kill -9 {}'.format(pid))
Run Code Online (Sandbox Code Playgroud)
我知道这不是太聪明,但它确实有效.所以我只是想知道为什么这段代码在Windows上运行,但在Linux上运行失败.
例:
from multiprocessing import Process
import os
process=Process(target=foo,args=('bar',))
pid=process.pid
process.terminate() # works on Windows only
...
os.sytem('kill -9 {}'.format(pid)) # my replacements on Linux
Run Code Online (Sandbox Code Playgroud)
我的配置:python 3.2.0 build 88445; Linux的2.6.32-Debian的6.0.4
这是我的代码中的示例.我希望这就足够了.
def start_test(timestamp,current_test_suite,user_ip):
global_test_table[timestamp] = current_test_suite
setattr(global_test_table[timestamp], "user_ip", user_ip)
test_cases = global_test_table[timestamp].test_cases_table
test_cases = test_cases*int(global_test_table[timestamp].count + 1)
global_test_table[timestamp].test_cases_table = test_cases
print(test_cases)
print(global_test_table[timestamp].test_cases_table)
case_num = len(test_cases)
Report.basecounter = Report.casecounter = case_num
setattr(global_test_table[timestamp], "case_num", case_num)
setattr(global_test_table[timestamp], "user_current_test", 0)
try:
dbobj=MySQLdb.connect(*dbconnector)
dbcursor=dbobj.cursor()
dbcursor.execute(sqlquery_insert_progress.format(progress_timestamp …Run Code Online (Sandbox Code Playgroud)