Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Copy dependency code into Pegasus.vendor directory.

Code Block
languagepy
themeRDark
# Instead of this
import six

# Use this
import Pegasus.vendor.six

...

Will run unit tests on the minimal supported Python version and above.

Using pytest instead of unittest

Uses assert instead of self.assert*.

Code Block
languagepy
themeRDark
import pytest

# Simple method, no need for classes
def test_method():
  # Simple assert, no need for assertEqual, etc.
  assert a % 2 == 0, "value was odd, should be even"

  with pytest.raises(ZeroDivisionError):
        1 / 0

# One method, multiple tests
# https://docs.pytest.org/en/latest/parametrize.html
@pytest.mark.parametrize(
    "a, b",
    [
		(1, 2, 3),
		(2, 3, 5),
		(5, -100, -95),
	],
)
def test_eval(a, b, expected):
    assert a + b == expected

# Dependency Injection
@pytest.fixture(scope="function OR class OR module OR package OR session")
def client():
	import requests
 	s = requests.Session()
	s.get(".../login")
	yield return s # Yield can be replaced with return if no cleanup is required.
	s.get(".../logout")
    s.close()

def test_external(client):
  assert client.get("/endpoint-1")


See: https://docs.pytest.org/en/latest/contents.html