Python Pytest

Write fast, parametrized tests with fixtures and markers.

  • pytest
  • parametrize
  • fixture
  • conftest
  • python testing

Python Pytest

Write fast, parametrized tests with fixtures and markers.

Commands

CommandWhat it does
pytest -qRun the suite quietly
pytest -k "search and not slow"Select by name expression
pytest --maxfail=1 -xStop at first failure
@pytest.mark.parametrize("x,y", [...])One test, many cases
@pytest.fixtureReusable setup/teardown

Example

import pytest
@pytest.mark.parametrize("a,b,expected", [(1,2,3),(0,0,0)])
def test_add(a, b, expected):
    assert a + b == expected

FAQ

unittest vs pytest?

pytest runs unittest cases too, but needs far less boilerplate; fixtures beat setUp/tearDown for composition.

Where do fixtures live?

conftest.py per directory — auto-discovered, no imports needed.

자주 묻는 질문

unittest vs pytest?
pytest runs unittest cases too, but needs far less boilerplate; fixtures beat setUp/tearDown for composition.
Where do fixtures live?
conftest.py per directory — auto-discovered, no imports needed.

Python