pygame.tests
Pygame unit test suite package
Run the pygame unit test suite

从命令行运行测试套件包的一种快捷方法是使用Python-m选项导入GO子模块:

python -m pygame.tests [<test options>]

命令行选项--Help显示用法消息。可用选项对应于 pygame.tests.run()Run the pygame unit test suite 争论。

测试包的xxxx_est子模块是针对pyGame各个部分的单元测试套件。每个程序也可以作为主程序运行。如果测试(如CDROMTEST)是交互式的,则这很有用。

对于pyGame开发,测试套件可以从pyGame发行版根目录运行。计划 run_tests.py 虽然可以直接运行test/go.py,但为了方便起见,提供了。

模块级别标记控制单元测试运行中包含哪些模块。标记被分配给具有对应的<name>_tag s.py模块的单元测试模块。标记模块具有全局 __tags__, 标记名称的列表。例如, cdrom_test.py 有一个标记文件 cdrom_tags.py 包含一个具有“interactive”字符串的标记列表。‘Interactive’标签表示 cdrom_test.py 需要用户输入。它被排除在 run_tests.pypygame.tests.go 跑。另外两个被排除的标记是‘Ignore’和‘subProcess_Ignore’。这两个标记指示不会在特定平台上运行的单元测试,或者没有相应的pyGame模块可用。测试运行人员将列出每个排除的模块以及负责的标签。

pygame.tests.run()
Run the pygame unit test suite
run(*args, **kwds) -> tuple

位置参数(可选):

The names of tests to include. If omitted then all tests are run. Test names
need not include the trailing '_test'.

关键字参数:

incomplete - fail incomplete tests (default False)
nosubprocess - run all test suites in the current process
               (default False, use separate subprocesses)
dump - dump failures/errors as dict ready to eval (default False)
file - if provided, the name of a file into which to dump failures/errors
timings - if provided, the number of times to run each individual test to
          get an average run time (default is run each test once)
exclude - A list of TAG names to exclude from the run
show_output - show silenced stderr/stdout on errors (default False)
all - dump all results, not just errors (default False)
randomize - randomize order of tests (default False)
seed - if provided, a seed randomizer integer
multi_thread - if provided, the number of THREADS in which to run
               subprocessed tests
time_out - if subprocess is True then the time limit in seconds before
           killing a test (default 30)
fake - if provided, the name of the fake tests package in the
       run_tests__tests subpackage to run instead of the normal
       pygame tests
python - the path to a python executable to run subprocessed tests
         (default sys.executable)

返回值:

A tuple of total number of tests run, dictionary of error information.
The dictionary is empty if no errors were recorded.

默认情况下,各个测试模块在不同的子进程中运行。这重新创建了正常的假游戏使用,其中 pygame.init()pygame.quit() 在每次程序执行时只调用一次,避免了测试模块之间的不幸交互。此外,对测试执行设置了时间限制,因此冻结的测试在其时间分配到期时被终止。如果线程不能正常工作或测试耗时太长,请使用单进程选项。不能保证所有测试都能在单进程模式下通过。

如果随机化参数为True或提供了种子参数,则测试以随机顺序运行。如果未提供种子整数,则使用系统时间。

各个测试模块可能具有 __tags__ 属性,一个标记字符串列表,用于有选择地从运行中省略模块。默认情况下,只有CDROM_TEST等交互模块会被忽略。交互模块必须作为Python程序从控制台运行。

此函数在每个Python会话中只能调用一次。它不是可重入的。




Edit on GitHub