Skip to content

Instantly share code, notes, and snippets.

@vonnenaut
Last active May 6, 2024 16:51
Show Gist options
  • Select an option

  • Save vonnenaut/0f4c083e8b31f4fada23d923c0c46e8a to your computer and use it in GitHub Desktop.

Select an option

Save vonnenaut/0f4c083e8b31f4fada23d923c0c46e8a to your computer and use it in GitHub Desktop.

Pytest

  • name must be test_[something].py
  • run via pyest
  • import files w/functions/methods to test:
    • from [filename] import [function] as [short name]

Example:

import pytest
from is_leap_year_A import is_leap_year as ilya
from is_leap_year_B import is_leap_year as ilyb

pytestmark = pytest.mark.parametrize("year, expected", [(2000, True), (2001, False)])
class TestClass:
    def test_a(self, year, expected):
        assert ilya(year) == expected

    def test_b(self, year, expected):
        assert ilyb(year) == expected
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment