PySys。关于从pysystest.xml读取数据(+在其上添加新属性)(v 0.9.2)

时间:2016-05-13 07:27:11

标签: python unit-testing

我想阅读每个测试用例的pysystest.xml文件中的所有数据集。以下是此类文件的示例:

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <pysystest state="runnable" type="auto">
        <description>
            <title>My testcase title</title>
            <purpose><![CDATA[My testcase description is this]]>
            </purpose>
        </description>
        <classification>
            <groups>
                <group>UAT</group>
            </groups>
        </classification>
        <data>
            <class module="run" name="PySysTest"></class>
        </data>
        <traceability>
            <requirements>
                <requirement></requirement>
            </requirements>
        </traceability>
    </pysystest>

框架中是否有API以便于阅读或者我必须解析整个XML文件?

我也有兴趣在它们上添加一些自定义属性,以便为它们的执行提供一些特定于测试用例的详细信息......框架是否支持这些文件的属性添加功能?

提前感谢您的帮助。

1 个答案:

答案 0 :(得分:1)

pysys.py启动器的打印帮助程序允许您打印详细信息;

C:\pysys.py print -h

PySys System Test Framework (version 1.1.0): Console print test helper

Usage: pysys.py print [option]* [tests]*
    where options include;
       -h | --help                 print this message
       -f | --full                 print full information
       -g | --groups               print test groups defined
       -d | --modes                print test modes defined
       -r | --requirements         print test requirements covered
       -m | --mode      STRING     print tests that run in user defined mode
       -a | --type      STRING     print tests of supplied type (auto or manual, default all)
       -t | --trace     STRING     print tests which cover requirement id
       -i | --include   STRING     print tests in included group (can be specified multiple times)
       -e | --exclude   STRING     do not print tests in excluded group (can be specified multiple times)

   and where [tests] describes a set of tests to be printed to the console. Note that multiple test
   sets can be specified, and where none are given all available tests will be run. If an include
   group is given, only tests that belong to that group will be printed. If an exclude group is given,
   tests in the group will not be run. The following syntax is used to select a test set;

       test1    - a single testcase with id test1
       :test2   - upto testcase with id test2
       test1:   - from testcase with id test1 onwards
       id1:id2  - all tests between tests with ids test1 and test2

   e.g.
       pysys.py -i group1 -e group2 --full test1:test3

因此,如果您执行pysys.py print -f,则会将完整信息输出到stdout。然后,您还可以在范围中打印测试,或在组中定义的测试或覆盖特定要求的测试等。如果要以编程方式解析描述符,可以使用pysys.xml包中的XMLDescriptorParser类。使用文件名创建,然后在该类中有访问器来检索值。