Python में Testing का परिचय
Alexander Levin
Data Scientist
सामान्य समस्याएँ:
इन समस्याओं से फिक्स करने की लागत काफी बढ़ सकती है.
टेस्टिंग से मदद मिलती है:
हमें यह जाँचने के लिए टेस्टिंग चाहिए कि यह तय आवश्यकताओं को पूरा करता है
Test - सॉफ्टवेयर एप्लिकेशन या सिस्टम की सही कार्यक्षमता सत्यापित करने की प्रक्रिया
assert स्टेटमेंट्सहवाई जहाज़ के बारे में सोचें:
ये सब — टेस्ट हैं! और सुरक्षा के लिए ज़रूरी हैं.

assert condition - यह जाँचने देता है कि condition True है.condition False है, तो Python AssertionError उठाएगा.pytest - Python का एक पॉपुलर टेस्टिंग फ्रेमवर्क, जो टेस्ट लिखना सरल बनाता है.
pytest में लिखा एक "assert" टेस्ट उदाहरण:
import pytest
# A function to test
def squared(number):
return number * number
# A test function always starts with "test"
def test_squared():
assert squared(-2) == squared(2)
with स्टेटमेंट के साथ उपयोग करते हैं# फाइल में लिखने का उदाहरण
with open("hello_world.txt", 'w') as hello_file:
hello_file.write("Hello world \n")
pytest.raises - जब आप उम्मीद करते हैं कि टेस्ट में Exception उठेगा
import pytest
# A function to test
def division(a, b):
return a / b
# A test function
def test_raises():
with pytest.raises(ZeroDivisionError):
division(a=25, b=0)
Testing यह है:
Tests का इम्प्लिमेंटेशन:
pytest - एक शक्तिशाली Python फ्रेमवर्क जो टेस्टिंग सरल करता हैassert - Python कीवर्ड, pytest में कंडीशन वेलिडेट कर बेसिक टेस्ट बनाने हेतुpytest.raises - एक कॉन्टेक्स्ट मैनेजर, जिससे ऐसा टेस्ट बनता है जहाँ Exception अपेक्षित होPython में Testing का परिचय