#!/usr/bin/python3 # -*- coding: utf-8 -*- """ pytest and nose (third party) Running pytest without mentioning a filename will run all files of format test_*.py or *_test.py in the current directory and subdirectories. Pytest automatically identifies those files as test files. We can make pytest run other filenames by explicitly mentioning them. Pytest requires the test function names to start with test. Function names which are not of format test* are not considered as test functions by pytest. We cannot explicitly make pytest consider any function not starting with test as a test function. Note: Debugging requires this line: """ import pudb # type: ignore pu.db # type: ignore import pytest # type: ignore # Example 1: def func(x: int) -> int: return x + 1 def test_answer() -> None: x = 3 assert func(3) == 4, "failed" def test_answer2() -> None: x = 3 assert func(3) == 5, "failed" # Eaxmple 2: def test_sum() -> None: assert sum([1, 2, 3]) == 6, "Should be 6" def test_sum_tuple() -> None: assert sum((1, 2, 2)) == 6, "Should be 6" # Example 3: class TestClass: def test_one(self) -> None: x = "this" assert "h" in x def test_two(self) -> None: x = "hello" assert hasattr(x, "check") """ note: these can be run by executing at bash $ python -m pytest -v yourscript.py $ py.test -v yourscript.py $ pytest -v # if your files are named test_ $ pytest yourfile.py or, running this when you want: """ if __name__ == "__main__": # Does this line not work? pytest.main()