Python में Testing का परिचय
Alexander Levin
Data Scientist
घातांक ऑपरेटर का टेस्ट:
# test_sqneg.py
import unittest
# Declaring the TestCase class
class TestSquared(unittest.TestCase):
# Defining the test
def test_negative(self):
self.assertEqual((-3) ** 2, 9)
CLI कमांड:
python3 -m unittest test_sqneg.py
मॉड्यूल unittest के साथ Python स्क्रिप्ट test_sqneg.py चलाएँ.
कमांड:
python3 -m unittest test_sqneg.py
टेस्ट आउटपुट:

unittest -k - दिए गए पैटर्न या सबस्ट्रिंग से मेल खाते टेस्ट मेथड/क्लास चलाएँ
Command:
python3 -m unittest -k "SomeStringOrPattern" test_script.py
Example:
python3 -m unittest -k "Squared" test_sqneg.py
Output:

unittest -f - पहली त्रुटि या फेल पर टेस्ट रन रोकें.
Command: python3 -m unittest -f test_script.py
Use case example: जब सभी टेस्ट अहम हों, जैसे उड़ान से पहले एयरप्लेन की जाँच.

कैच फ्लैग unittest -c - "Ctrl - C" दबाकर टेस्ट को इंटरप्ट करने देता है.
unittest वर्तमान टेस्ट के ख़त्म होने तक रुकता है और अब तक के नतीजे दिखाता है.unittest KeyboardInterrupt exception उठाता है.Command: python3 -m unittest -c test_script.py
Use case example: बड़े टेस्ट सूट को डिबग करते समय
unittest -v - टेस्ट अधिक विवरण के साथ चलाएँ
Command: python3 -m unittest -v test_script.py.
Use case example: डिबगिंग उद्देश्यों के लिए
Output example: 
बिना आर्गुमेंट का बेसिक कमांड python3 -m unittest test_script.py
unittest में आउटपुट
कीवर्ड आर्गुमेंट: python3 -m unittest -k "SomeStringOrPattern" test_script.py
फेल फास्ट फ्लैग: python3 -m unittest -f test_script.py
कैच फ्लैग: python3 -m unittest -c test_script.py
वर्बोज़ फ्लैग: python3 -m unittest -v test_script.py
Python में Testing का परिचय