"""1.在 book 目录下新增 setup.py """ # 内容如下: # from setuptools import setup # from setuptools import find_packages # # setup(name="utils", packages=find_packages()) """2.在 book 目录下新增和 setup.py 同级的目录src,在src下新建 utils包,在utils包下新增 max.py (被测文件)""" # 内容如下: # def max(values): # maxvalue = values[0] # # for val in values: # if val > max: # maxvalue = val # # return maxvalue """3.在 utils包下新建 tests包,在该包下新增 测试函数(test_max)和断言""" # 具体如下: # def test_max(): # values = (2, 3, 1, 4, 7, 9) # val =max(values) # assert val == 7 """4. src 目录下执行 pytest --pyargs utils""" # PS E:\learnPython\01_01_pytest_book\src> pytest --pyargs utils # ================================================= test session starts ============================================= # platform win32 -- Python 3.11.3, pytest-7.4.2, pluggy-1.3.0 # rootdir: E:\learnPython\01_01_pytest_book # collected 1 item # # utils\tests\test_max.py F [100%] # # ====================================================== FAILURES =================================================== # ______________________________________________________ test_max ___________________________________________________ # # def test_max(): # values = (2, 3, 1, 4, 7, 9) # val =max(values) # > assert val == 7 # E assert 9 == 7 # # utils\tests\test_max.py:4: AssertionError # =============================================== short test summary info =========================================== # FAILED utils\tests\test_max.py::test_max - assert 9 == 7 # ================================================== 1 failed in 0.20s ==============================================
pytest学习实践-day12 :执行指定包的用例
于 2024-04-10 15:31:30 首次发布