PyTest-BDD:支持不带方案大纲的数据表

PyTest-BDD : Support for data tables without Scenario Outline

我有以下图像作为测试用例

user settings](https://drive.google.com/open?id=1N9w5qaqC8AYUo5Sa2lvmsvqHLCgiPE8a)[![enter image description here] 1

使用行为时,我们正在编写这样的方案

1
2
3
4
5
6
7
8
9
10
Given When user is logged in to the platform
When user opens the settings window
Then user should see the following values
    | Field                 | Value              |
    | Currency              | Reported currency  |
    | Conversion Method     | MI recommended     |
    | Magnitude             | Millions (6)       |
    | Display Null Value As | SOA_Null           |
    | Function Options      | Excluded from export |
    | Dynamic Field Labels  | Excluded from export |

我们现在正在迁移到Pytest-BDD,而不是行为。 但是我在Pytest中找不到上述案例的支持。 我浏览了Pytest-BDD文档,他们对方案大纲的支持。

https://pytest-bdd.readthedocs.io/en/latest/

但是我的情况不是方案大纲,因为我只需要运行一次此方案,而不必遍历上述字段-值对

我也查看了github,发现最接近的是github,但这似乎尚未获得批准。

https://github.com/pytest-dev/pytest-bdd/pull/180

Pytest是否以任何方式支持上述方案的实现? 是否有解决方法(如果不是直接方法)来解决?


希望这可以帮助...

然后,响应应具有以下属性:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
    |  attr                     |
    |  id                       |
    |  activityId               |
    |  activityName             |
    |  activityType             |
    |  processDefinitionId      |
    |  processDefinitionUrl     |
    |  processInstanceId        |
    |  processInstanceUrl       |
    |  executionId              |
    |  taskId                   |
    |  calledProcessInstanceId  |
    |  assignee                 |
    |  startTime                |
    |  endTime                  |
    |  durationInMillis         |
    |  tenantId                 |


Then verify response attribute values:
    |attr             |   attr_value        | path                  |
    |activityId       |   endProcessSubmit  | data[0].activityId    |
    |activityType     |   endEvent          | data[0].activityType  |

@then(parsers.parse('响应应具有以下属性:\ n {attr_table}'))

def verify_response_attributes(datatable,attr_table,query_historic_activity_instances):
query_data = query_historic_activity_instances.json()['数据']
BaseTest.verify_tbl_attr(attr_table,query_data)

@then(parsers.parse('验证响应属性值:\ n {attr_value_table}'))

def verify_response_attribute_values(datatable,attr_value_table,query_historic_activity_instances):
query_data = query_historic_activity_instances.json()
BaseTest.verify_tbl_attr_values(attr_value_table,query_data)

@staticmethod
def verify_tbl_attr_values(table_with_header,query_data):
#datatable = parse_str_table(attr_value_table)
list_attr = BaseTest.get_tbl_attr_values(table_with_header)
#范围内的行(len(datatable.rows)):
#attr = list(datatable.rows [row] .values())[0]
#attr_val = list(datatable.rows [row] .values())[1]
#path = list(datatable.rows [row] .values())[2]
对于我在范围内(len(list_attr)):
attr = list_attr [i] [0]
attr_val = list_attr [i] [1]
路径= list_attr [i] [2]
用于parse(path).find(query_data)中的匹配:
assert attr_val == match.value,"%s Dint匹配的预期%s和实际%s"%(
attr_val,match.value,attr)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
@staticmethod
def get_tbl_attr_values(table_with_header):
    datatable = parse_str_table(table_with_header)
    list_attr_val = []
    for row in range(len(datatable.rows)):
        list_attr_val.append(list(datatable.rows[row].values()))
    return list_attr_val

@staticmethod
def verify_tbl_attr(table_with_header,query_data):
    list_attr = BaseTest.get_tbl_attr(table_with_header)
    for i in range(len(query_data)):
        for j in range(len(list_attr)):
            assert list_attr[j] in query_data[i],"Response don't have %s" % list_attr[j]

@staticmethod
def get_tbl_attr(table_with_header):
    datatable = parse_str_table(table_with_header)
    list_attr = []
    for row in datatable.rows:
        for item in row:
            list_attr.append(row[item])
    return (list_attr)

@staticmethod
def verify_tbl_attr_by_column(table_with_header):
    datatable = parse_str_table(table_with_header)
    list_attr = []
    for column in datatable.columns.values():
            list_attr.append(column)
    return (list_attr)