运行测试用例

import pytest
from WXP2P_2.test_data2.login_case import logindata_error1,logindata_error2,logindata_right
class TestLogin:
    """测试登录"""

    @pytest.mark.parametrize("data",logindata_error1)#装饰测试用例。
    @pytest.mark.wrong
    def test_error1(self,data,int_start):
        """错误信息"""
        int_start[0].login(data["use"],data["password"])
        try:
            assert (int_start[0].error_value()==data["expected"])
            print("测试用例通过,预期结果{}与实际结果{}一致".format(data["expected"],int_start[0].error_value()))
        except AssertionError as e:
            print("用例失败")
            raise e
        finally:
           int_start[0].clear()#清空输入框
        # Login().login(data["use"], data["password"])#错误示范,这种调用方法,会多次打开浏览器
        # Login().clear()#错误示范,这种调用方法,会多次打开网页
#     @pytest.mark.parametrize("data",logindata_error2)
#     def test_error2(self, data):
#         """错误信息"""
#         self.login.login(data["use"], data["password"])
#         try:
#             assert (self.login.error_value1() == data["expected"])
#             print("测试用例通过,预期结果{}与实际结果{}一致".format(data["expected"], self.login.error_value1()))
#         except AssertionError as e:
#             print("用例失败")
#             raise e
#         finally:
#             self.login.clear()  # 清空输入框
#     @pytest.mark.ok
#     @pytest.mark.parametrize("data",logindata_right)#装饰测试用例
#     def test_right(self,data):
#         """正确的信息登录"""
#         self.login.login(data["use"], data["password"])
#         try:
#             assert (data["expected"] in self.login.right_value())
#             print("测试用例通过,预期结果{}与实际结果{}一致".format(data["expected"], self.login.right_value()))
#         except AssertionError as e:
#             print("用例失败")
#             raise e
#         # Login().login(data["use"], data["password"])#错误示范,这种调用方法,会多次打开网页
if __name__ == '__main__':
    pytest.main(["-m wrong","-s"])

执行结果

Traceback (most recent call last):
  File "D:/WX_P2P_ITEM/WXP2P_2/test_login.py", line 46, in <module>
    pytest.main(["-m wrong","-s"])
  File "D:\Python\lib\site-packages\_pytest\config\__init__.py", line 60, in main
    config = _prepareconfig(args, plugins)
  File "D:\Python\lib\site-packages\_pytest\config\__init__.py", line 204, in _prepareconfig
    pluginmanager=pluginmanager, args=args
  File "D:\Python\lib\site-packages\pluggy\hooks.py", line 289, in __call__
    return self._hookexec(self, self.get_hookimpls(), kwargs)
  File "D:\Python\lib\site-packages\pluggy\manager.py", line 68, in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
  File "D:\Python\lib\site-packages\pluggy\manager.py", line 62, in <lambda>
    firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
  File "D:\Python\lib\site-packages\pluggy\callers.py", line 203, in _multicall
    gen.send(outcome)
  File "D:\Python\lib\site-packages\_pytest\helpconfig.py", line 93, in pytest_cmdline_parse
    config = outcome.get_result()
  File "D:\Python\lib\site-packages\pluggy\callers.py", line 80, in get_result
    raise ex[1].with_traceback(ex[2])
  File "D:\Python\lib\site-packages\pluggy\callers.py", line 187, in _multicall
    res = hook_impl.function(*args)
  File "D:\Python\lib\site-packages\_pytest\config\__init__.py", line 684, in pytest_cmdline_parse
    self.parse(args)
  File "D:\Python\lib\site-packages\_pytest\config\__init__.py", line 901, in parse
    self._preparse(args, addopts=addopts)
  File "D:\Python\lib\site-packages\_pytest\config\__init__.py", line 846, in _preparse
    self.pluginmanager.load_setuptools_entrypoints("pytest11")
  File "D:\Python\lib\site-packages\pluggy\manager.py", line 282, in load_setuptools_entrypoints
    self.register(plugin, name=ep.name)
  File "D:\Python\lib\site-packages\_pytest\config\__init__.py", line 318, in register
    ret = super(PytestPluginManager, self).register(plugin, name)
  File "D:\Python\lib\site-packages\pluggy\manager.py", line 102, in register
    hook._maybe_apply_history(hookimpl)
  File "D:\Python\lib\site-packages\pluggy\hooks.py", line 336, in _maybe_apply_history
    res = self._hookexec(self, [method], kwargs)
  File "D:\Python\lib\site-packages\pluggy\manager.py", line 68, in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
  File "D:\Python\lib\site-packages\pluggy\manager.py", line 62, in <lambda>
    firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
  File "D:\Python\lib\site-packages\pluggy\callers.py", line 208, in _multicall
    return outcome.get_result()
  File "D:\Python\lib\site-packages\pluggy\callers.py", line 80, in get_result
    raise ex[1].with_traceback(ex[2])
  File "D:\Python\lib\site-packages\pluggy\callers.py", line 187, in _multicall
    res = hook_impl.function(*args)
  File "D:\Python\lib\site-packages\allure_pytest\plugin.py", line 21, in pytest_addoption
    help="Generate Allure report in the specified directory (may not exist)")
  File "D:\Python\lib\site-packages\_pytest\config\argparsing.py", line 303, in addoption
    raise ValueError("option names %s already added" % conflict)
ValueError: option names {'--alluredir'} already added

这是因为pytest-allure-adaptor与allure-pytest的alluredir都被引用造成冲突

需要卸载pytest-allure-adaptor


卸载完成后,再执行测试模块

============================= test session starts =============================
platform win32 -- Python 3.6.3, pytest-4.5.0, py-1.8.0, pluggy-0.11.0
rootdir: D:\WX_P2P_ITEM\WXP2P_2
plugins: allure-pytest-2.6.5
collected 5 items / 3 deselected / 2 selected

test_login.py 测试用例通过,预期结果请输入正确的手机号与实际结果请输入正确的手机号一致
.测试用例通过,预期结果请输入手机号与实际结果请输入手机号一致
.

最新文章

  1. Codeforces Round #344 (Div. 2) A. Interview
  2. LINQ系列:Linq to Object限制操作符
  3. Java获取XML节点总结之读取XML文档节点
  4. PHP如何判断一个数组是一维数组或者是二维数组?用什么函数?
  5. 菜鸟学自动化测试(八)----selenium 2.0环境搭建(基于maven)
  6. span width无效
  7. TYVJ P1034 尼克的任务 Label:倒推dp
  8. github 修改fork的代码之后如何提交代码并pull request
  9. MongoDB 数据类型
  10. Mac使用指南
  11. struts2+jquery+ajax实现上传&amp;&amp;校验实例
  12. java cmd常用命令
  13. 工作中小知识点汇总(sql)
  14. 将json的时间格式转换成正常的时间格式
  15. SCRIPT7002: XMLHttpRequest: 网络错误 0x2ef3, 由于出现错误 00002ef3&amp;nbsp
  16. 在Python3.5中使用 The del.icio.us API
  17. 《HelloGitHub》第 29 期
  18. Linux下删除乱码文件
  19. ASP.NET Core使用log4net记录日志
  20. React child

热门文章

  1. xml的的特殊字符转义&amp;
  2. httpd基础
  3. UVa 11825 Hackers&#39; Crackdown (状压DP)
  4. 牛客 - 17968 - xor序列 - 线性基
  5. 怎样让自定义Cell的图片和文本自适应高度
  6. poj3276 Face The Right Way
  7. Luogu P1514引水入城【搜索】 By cellur925
  8. java模拟进程调度之模拟抢占试多级轮转调度(附带可视化解决方案)
  9. ADO winform注册
  10. redis连接错误