疑惑点:
- Factories as fixtures 的应用场景是怎么样的?
- 为什么make_customer_record(“Lisa”) ,接收Lisa字符串不是make_customer_record而是_make_customer_record?可以直接跳过第一个函数吗?
- 返回给test_customer_records的是一个函数,那make_customer_record(“Lisa”)是直接调用返回的 _make_customer_record函数吗?为什么不是再从make_customer_record进一次,这个逻辑不太懂
- 以下两种方式有什么不同?
@pytest.fixture
def make_customer_record():
def _make_customer_record(name):
return {"name": name, "orders": []}
return _make_customer_record
def test_customer_records(make_customer_record):
customer_1 = make_customer_record("Lisa")
customer_2 = make_customer_record("Mike")
customer_3 = make_customer_record("Meredith")
def make_customer_record(name):
def _make_customer_record(name):
return {"name": name, "orders": []}
return _make_customer_record(name)
def test_customer_records():
customer_1 = make_customer_record("Lisa")
print(customer_1)
customer_2 = make_customer_record("Mike")
print(customer_2)
customer_3 = make_customer_record("Meredith")
print(customer_3)