How to make a class or test function with pytest?

1

Be a program in Python, such as fibonacci calculus:

def fibR(n):
 if n==1 or n==2:
  return 1
 return fib(n-1)+fib(n-2)
print (fibR(5))

How to make a test class / function using pytest, for example?

    
asked by anonymous 06.08.2016 / 03:38

1 answer

1
def fibR(n):
 if n==1 or n==2:
  return 1
 return fibR(n-1)+fibR(n-2)

In the same directory: test_fib.py:

import pytest
from fib import fibR

def test_fib_1_equals_1():
    assert fibR(1) == 1

def test_fib_2_equals_1():
    assert fibR(2) == 1

def test_fib_6_equals_8():
    assert fibR(6) == 8

@Tagc's response to the stackoverflow English version.

    
07.08.2016 / 02:28