如何只用assertTrue跟 @allure.story('用户登陆') @allure.title('测试数据') @pytest.mark.parametrize("arg", user_info) @logs def test01_login(self,driver): page = Test_Login_method(driver) res= Test_Login_method.test01_login_method(arg[0],arg[1])代码设置断言
时间: 2024-02-06 16:04:12 浏览: 28
可以在`test01_login_method`方法中添加断言来判断登录是否成功,然后将断言结果作为返回值,再在`test01_login`方法中使用`assertTrue`来断言这个返回值。
示例代码如下:
```
import allure
import pytest
@allure.story('用户登陆')
@allure.title('测试数据')
@pytest.mark.parametrize("arg", user_info)
@logs
def test01_login(self, driver):
page = Test_Login_method(driver)
res = Test_Login_method.test01_login_method(arg[0], arg[1])
assert res, "登录失败" # 断言登录是否成功
self.assertTrue(res)
```
相关问题
> self.assertTrue(res) E AttributeError: 'TestLogin' object has no attribute 'assertTrue'
这个错误提示表明在你的测试类中缺少 `assertTrue` 方法。`assertTrue` 是 Python unittest 模块中的一个断言方法,用于判断某个条件是否为真。你需要在你的测试类中导入 unittest 模块,并继承 `unittest.TestCase` 类。例如:
```
import unittest
class TestLogin(unittest.TestCase):
def test_login(self):
res = login('username', 'password')
self.assertTrue(res)
```
这样就可以使用 `assertTrue` 方法了。
@Test public void givenPizaOrder_whenReady_thenDeliverable() { Pizza testPz = new Pizza(); testPz.setStatus(Pizza.PizzaStatus.READY); assertTrue(testPz.isDeliverable()); }
这段代码是一个测试方法,用于验证当披萨的状态为READY时,披萨是否可以交付。
在测试方法中,首先创建了一个Pizza对象testPz。然后通过调用setStatus()方法将testPz的状态设置为PizzaStatus.READY。接下来,使用assertTrue()方法来断言testPz对象的isDeliverable()方法返回的结果应为true。
如果测试通过,即当披萨状态为READY时,isDeliverable()方法返回true,那么测试方法就会顺利通过。否则,如果isDeliverable()方法返回false,测试方法将抛出断言异常。
相关推荐
![](https://img-home.csdnimg.cn/images/20210720083646.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)