Python में Testing का परिचय
Alexander Levin
Data Scientist
पिकनिक की तैयारी सोचिए:
Fixtures से मदद मिलती है:
मान लीजिए हमारे पास:
list वैरिएबल data नाम सेdata = [0, 1, 1, 2, 3, 5, 8, 13, 21]और हम test करना चाहते हैं कि:
5 और 21 मौजूद हैंimport pytest
# Fixture decorator
@pytest.fixture
# Fixture for data initialization
def data():
return [0, 1, 1, 2, 3, 5, 8, 13, 21]
def test_list(data):
assert len(data) == 9
assert 5 in data
assert 21 in data
उदाहरण का आउटपुट:

Fixture इस्तेमाल करने के लिए ये करें:
@pytest.fixture डेकोरेटर घोषित करेंहमने testing fixtures के बारे में सीखा:
list की तैयारी@pytest.fixture घोषित कर pytest fixture परिभाषित करेंPython में Testing का परिचय