报错代码:
import pytest
import allure
@allure.feature("登录")
class TestLogin():
@allure.story("登录成功")
def test_login_success(self):
print("登录成功")
pass
@allure.story("密码错误")
def test_login_failure(self):
with allure.step("输入用户名"):
print("输入用户名")
with allure.step("输入密码"):
print("输入密码")
print("点击登录")
with allure.step("登录失败"):
assert '1' == 1
print("登录失败")
pass
@allure.story("用户名密码错误")
def test_login_failure_a(self):
print("用户名或者密码错误,登录失败")
pass
@allure.feature("注册")
class TestRegister():
@allure.story("注册成功")
def test_register_success(self):
print("测试用例:注册成功")
pass
@allure.story("注册失败")
def test_register_failure(self):
with allure.step("输入用户名"):
print("输入用户名")
with allure.step("输入密码"):
print("输入密码")
with allure.step("再次输入密码"):
print("再次输入密码")
print("点击注册")
with allure.step("注册失败"):
assert 1 + 1 == 2
print("注册失败")
pass
报错信息如下:
E File "E:\PycharmProjects\api_demo\script\test_feature_story_step.py", line 4
E SyntaxError: (unicode error) 'utf-8' codec can't decode byte 0xb5 in position 0: invalid start byte
解决方法:
代码上方加上:
#!/usr/bin/python3
# coding=gbk
起初# -*- coding:utf-8 -*- 再运行还是报错,加上#coding=gbk问题完美解决
#!/usr/bin/python3
# coding=gbk
import pytest
import allure
@allure.feature("登录")
class TestLogin():
@allure.story("登录成功")
def test_login_success(self):
print("登录成功")
pass
@allure.story("密码错误")
def test_login_failure(self):
with allure.step("输入用户名"):
print("输入用户名")
with allure.step("输入密码"):
print("输入密码")
print("点击登录")
with allure.step("登录失败"):
assert '1' == 1
print("登录失败")
pass
@allure.story("用户名密码错误")
def test_login_failure_a(self):
print("用户名或者密码错误,登录失败")
pass
@allure.feature("注册")
class TestRegister():
@allure.story("注册成功")
def test_register_success(self):
print("测试用例:注册成功")
pass
@allure.story("注册失败")
def test_register_failure(self):
with allure.step("输入用户名"):
print("输入用户名")
with allure.step("输入密码"):
print("输入密码")
with allure.step("再次输入密码"):
print("再次输入密码")
print("点击注册")
with allure.step("注册失败"):
assert 1 + 1 == 2
print("注册失败")
pass
再次运行程序成功!!!