Introduction
Good test names help you and others understand what the test checks. Clear names make finding and fixing problems faster.
Jump into concepts and practice - no test required
Good test names help you and others understand what the test checks. Clear names make finding and fixing problems faster.
def test_function_name(): assert something == expected
Test functions must start with test_ so pytest can find them.
Use descriptive names that explain what the test checks.
def test_add_two_numbers(): assert add(2, 3) == 5
def test_login_with_valid_credentials(): assert login('user', 'pass') is True
import pytest def test_divide_by_zero_raises_error(): with pytest.raises(ZeroDivisionError): divide(5, 0)
This script has three tests for the add function. Each test name clearly says what it checks.
import pytest def add(a, b): return a + b def test_add_positive_numbers(): assert add(1, 2) == 3 def test_add_negative_numbers(): assert add(-1, -1) == -2 def test_add_zero(): assert add(0, 5) == 5
Always start test function names with test_ so pytest can detect them.
Use underscores to separate words for readability.
Keep names short but descriptive enough to understand the test purpose.
Test names must start with test_ for pytest to find them.
Good names describe what the test checks in simple words.
Clear test names help with debugging and teamwork.
test_.test_, so pytest will find it automatically.def test_addition():
assert 1 + 1 == 2
def check_subtraction():
assert 2 - 1 == 1
def testMultiplication():
assert 2 * 3 == 6
class TestDivision:
def test_divide(self):
assert 6 / 2 == 3
test_ and methods inside classes named Test* starting with test_.test_addition is found; check_subtraction is ignored; testMultiplication is ignored due to camelCase; test_divide inside TestDivision class is found.Test_login but pytest does not run it. What is the most likely reason?test_ exactly.Test_loginT, so pytest ignores it.