[英]Why I can't use method from one of my .py files in another .py file?
This is my code for form with button: 这是我的带有按钮的表单代码:
import sys
from ClickerBot import test_ClikerBot
def func1():
if sys.version_info < (3, 0):
# Python 2
import Tkinter as tk
else:
# Python 3
import tkinter as tk
root = tk.Tk()
root.title(“Clicker”)
def startClick():
root.destroy()
clicker = test_ClikerBot()
clicker.test_clicker_bot()
button1 = tk.Button(root, text=“CLICK CLICK CLICK”, command=startClick())
button1.pack()
tk.mainloop()
if __name__ == ‘__main__‘:
func1()
When I start this file, I receive next error: 当我启动此文件时,我收到下一个错误:
/System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7 /Users/ltst/Desktop/dev/DribbleBot/venv/Scripts/main.py
Traceback (most recent call last):
File “/Users/ltst/Desktop/dev/DribbleBot/venv/Scripts/main.py”, line 23, in <module>
func1()
File “/Users/ltst/Desktop/dev/DribbleBot/venv/Scripts/main.py”, line 19, in func1
button1 = tk.Button(root, text=“CLICK CLICK CLICK”, command=startClick())
File “/Users/ltst/Desktop/dev/DribbleBot/venv/Scripts/main.py”, line 16, in startClick
clicker = test_ClikerBot()
File “/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/unittest/case.py”, line 191, in __init__
(self.__class__, methodName))
ValueError: no such test method in <class ‘ClickerBot.test_ClikerBot’>: runTest
But in my ClickerBot class exist this method: 但是在我的ClickerBot类中存在此方法:
class test_ClikerBot(unittest.TestCase):
def test_clicker_bot(self):
Where is problem? 问题在哪里? I import this code from catalog studio recorder, and start learn python a week ago, because many things for me like magic and google help not every time (Sorry for bad English) 我从Catalog Studio记录器导入此代码,并在一周前开始学习python,因为对我来说,魔术和Google等许多功能并非每次都提供帮助(对不起,英语不好)
Your code would be ok if your test_ClikerBot
class was an ordinary class. 如果您的test_ClikerBot
类是普通类,那么您的代码就可以了。 The point is that unittest
is a very special framework, and TestCase
classes are not meant to be used directly, but thru a TestRunner
and a TestLoader
that both do quite some magic under the hood. 关键是unittest
是一个非常特殊的框架,并且TestCase
类不是要直接使用的,而是通过TestRunner
和TestLoader
,它们在TestLoader
都TestLoader
了很大的作用。 This is partly documented , but you'll probably have to read the source code of the existing runners and loaders to really find out how to make the whole thing work. 这部分记录在案 ,但是您可能必须阅读现有的运行程序和装载程序的源代码,才能真正了解如何使整个工作正常进行。 A good starting point might be the already existing GUI testrunner mentionned in the doc: 一个好的起点可能是文档中提到的已经存在的GUI testrunner:
The script Tools/unittestgui/unittestgui.py in the Python source distribution is a GUI tool for test discovery and execution Python源代码分发中的脚本Tools / unittestgui / unittestgui.py是用于测试发现和执行的GUI工具
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.