gpt4 book ai didi

python - 为什么这个简单 bool 逻辑的 pytest 失败了?

转载 作者:行者123 更新时间:2023-11-28 21:15:34 24 4
gpt4 key购买 nike

<分区>

我不明白为什么我对以下函数的 pytest 没有通过:

解决方案/_and.py

def _and(a, b):
if a:
return b
return False

测试和.py

_and_path='./solutions/'
import itertools
import sys
sys.path.append(_and_path)
print(sys.path)
import _and


def test_and():
for i, j in itertools.product([True, False], [True, False]):
assert(_and._and(i, j) == i and j)

失败报告:

pytest
================================================= test session starts =================================================
platform win32 -- Python 3.6.4, pytest-5.2.4, py-1.8.0, pluggy-0.13.0
rootdir: C:\Users\Joseph\projects\byoc
collected 2 items

test_and.py .F [100%]

====================================================== FAILURES =======================================================
______________________________________________________ test_and _______________________________________________________

def test_and():
for i, j in itertools.product([True, False], [True, False]):
> assert(_and._and(i, j) == i and j)
E assert (False == True)
E + where False = <function _and at 0x000001F2A5ED7BF8>(True, False)
E + where <function _and at 0x000001F2A5ED7BF8> = _and._and

test_and.py:14: AssertionError
============================================= 1 failed, 1 passed in 0.08s =============================================

我是 Pytest 的新手,但在我看来,我的 and 版本在 (True, False) 时返回 False是它的参数,但是测试中的 i 和 j 返回带有相同参数的 True。我错过了什么吗?

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com