pytest之将多个测试用例放在一个类中,生成唯一临时文件夹

将多个测试用例放在一个类中

简单来说就是将多个测试用例放到类中,通过pytest去管理,这和Testng很像。示例代码如下:

"""
将多个测试用例放到一个类中执行
"""


class TestClass(object):
    def test_1(self):
        assert 1 == 1

    def test_2(self):
        assert 'h' in "hello"

执行效果

创建唯一的临时文件夹

内置 fixtures 之 tmpdir:

tmpdir 的作用是:在本地生成临时文件夹,并返回文件对象;

先写个测试用例,调用 tmpdir,示例代码如下:

# -*- coding: utf-8 -*-
# @Time    : 2020/10/7 16:03
# @Author  : longrong.lang
# @FileName: test_tempdir.py
# @Software: PyCharm
# @Cnblogs :https://www.cnblogs.com/longronglang

class TestTempDir:
    def test_tempdir(self,tmpdir):
        print('
',tmpdir)

执行效果:

可以看到控制台有打印出生成的临时文件夹的目录,并且电脑本地也生成了文件夹!

原文地址:https://www.cnblogs.com/longronglang/p/13778259.html