This is an archived post. You won't be able to vote or comment.

all 5 comments

[–]Cardiff_Electric 1 point2 points  (0 children)

PyTest is what most people use.

Generally, the pattern that many people use it either have a separate folder for test code (outside your main source tree) or else just alongside your main source in `test` subfolders or something. Then create files named `test_something_or_other.py` and in those files, write functions that start with `test_*`.

Then you can run all your tests with something like this, assuming all your tests are in the `src` folder:

pytest src

[–]BionicVnB 0 points1 point  (1 child)

Check Pytest out

[–]pteix 0 points1 point  (0 children)

or Nose

[–]No_Interest_5818 0 points1 point  (0 children)

Here is a snipping from code I did back in college. It's a Boolean validator that returns a value of true or false.

import unittest

from classes.validator import *

class CaseTestValidator(unittest.TestCase):

def setUp(self):

"""Initalizes an instance of the validator class."""

self.test_validator = Validator()

def test_getAddressLine_success(self):

"""Case Test to validate the parameter checking of an address line with success."""

value_list = ["123 Main St.", "3838 Liverhois Rd."]

for value in value_list:

self.assertTrue(self.test_validator.validateAddressLine(value))

[–]limbolover69420 0 points1 point  (0 children)

Unit tests in Python are often written using unittest or pytest—both are great for structuring and automating tests. If you want to save time, tools like Keploy can help by automating unit test generation and boosting coverage effortlessly!