pytest自动化显然在测试收集阶段运行测试

时间:2012-05-11 21:02:03

标签: python selenium pytest

使用pytest和selenium运行webui自动化测试;遇到一个问题,我的测试似乎在集合阶段实际运行。在这个阶段,我希望pytest能够收集测试 - 而不是运行它们。最终结果是我最终得到6个测试结果,我希望2.现在有趣的部分,6个结果只出现在HTML报告中;在命令行中我只得到预期的2行输出(但是运行这两个测试需要300秒,因为测试实际上是多次运行)。

测试/ test_datadriven.py

#!/usr/bin/env python
from unittestzero import Assert
from pages.home import Home
from pages.administration import RolesTab
from api.api import ApiTasks
import time
import pytest

from data.datadrv import *

class TestRolesDataDriven(object):
    scenarios = [scenario1,scenario2]

    @pytest.mark.challenge
    def test_datadriven_rbac(self, mozwebqa, org, perm_name, resource, verbs, allowed, disallowed):
        """
Perform a data driven test related to role based access controls.
All parameters are fullfilled by the data.
:param org: Organization Name
:param perm_name: Permission name
:param resource: Resource
:param verbs: A tuple of verbs
:returns: Pass or Fail for the test
"""

        sysapi = ApiTasks(mozwebqa)
        home_page = Home(mozwebqa)
        rolestab = RolesTab(mozwebqa)

        role_name = "role_%s" % (home_page.random_string())
        perm_name = "perm_%s" % (home_page.random_string())
        username = "user%s" % home_page.random_string()
        email = username + "@example.com"
        password = "redhat%s" % (home_page.random_string())

        sysapi.create_org(org)
        sysapi.create_user(username, password, email)

        home_page.login()

        home_page.tabs.click_tab("administration_tab")
        home_page.tabs.click_tab("roles_administration")
        home_page.click_new()
        rolestab.create_new_role(role_name)

        rolestab.click_role_permissions()

        rolestab.role_org(org).click()
        rolestab.click_add_permission()

        rolestab.select_resource_type(resource)
        home_page.click_next()
        for v in verbs:
            home_page.select('verbs', v)
        home_page.click_next()

        rolestab.enter_permission_name(perm_name)
        rolestab.enter_permission_desc('Added by QE test.')
        rolestab.click_permission_done()

        rolestab.click_root_roles()
        rolestab.click_role_users()

        rolestab.role_user(username).add_user()

        home_page.header.click_logout()
        home_page.login(username, password)

        for t in allowed:
            Assert.true(t(home_page))

        for t in disallowed:
            Assert.false(t(home_page))

数据/ data.py

###
# DO NOT EDIT HERE
###

def pytest_generate_tests(metafunc):
    """
Parse the data provided in scenarios.
"""
    idlist = []
    argvalues = []
    for scenario in metafunc.cls.scenarios:
        idlist.append(scenario[0])
        items = scenario[1].items()
        argnames = [x[0] for x in items]
        argvalues.append(([x[1] for x in items]))
    metafunc.parametrize(argnames, argvalues, ids=idlist)
###
# EDIT BELOW
# ADD NEW SCENARIOS
###

scenario1 = ('ACME_Manage_Keys', { 'org': 'ACME_Corporation',
                                   'perm_name': 'ManageAcmeCorp',
                                   'resource': 'activation_keys',
                                   'verbs': ('manage_all',),
                                   'allowed': (Base.is_system_tab_visible,
                                               Base.is_new_key_visible,
                                               Base.is_activation_key_name_editable),
                                   'disallowed': (Base.is_dashboard_subs_visible,)})
scenario2 = ('Global_Read_Only', { 'org': 'Global Permissions',
                                   'perm_name': 'ReadOnlyGlobal',
                                   'resource': 'organizations',
                                   'verbs': ('read','create'),
                                   'allowed': (Base.is_organizations_tab_visible,
                                               Base.is_new_organization_visible,
                                               Base.is_new_organization_name_field_editable),
                                   'disallowed': (Base.is_system_tab_visible,
                                                  Base.is_new_key_visible)})

github提供完整的源代码; https://github.com/eanxgeek/katello_challenge

任何人都知道这里会发生什么?我正在使用pytest-mozwebqa插件,pytests和selenium。

谢谢!

1 个答案:

答案 0 :(得分:1)

检查已安装的pytest-mozwebqa的版本。如果您安装的版本是< 0.10然后你必须更新。

pip-python install --upgrade pytest-mozwebqa

由于pytest-mozwebqa的更改次数,我强烈建议您先在python virtualenv中进行测试。