dimanche 6 septembre 2015

Python - Unit testing functions that are dependant on previous functions outcome (Chained functions)

I have three inter-dependant python functions: f(), g(), and h() such as:

  • g() depends on the outcome of f().
  • h() depends on the outcome of g().
def f():
    ...

def g():
    f()
    ...

def h():
    g()
    ...

To unit test these functions I'm using py.test. In the way I'm trying to unit test, I'm observing some redundancy:

def test_f():
    assert f()

def test_g():
    f()
    assert g()

def test_h():
    g()
    assert h()

How should I design the Unit Tests, in this particular case?

Aucun commentaire:

Enregistrer un commentaire