Problem with Pytest

0

I'm trying to apply pytest on a project that uses the Bhaskara Formula, because it's giving it error and I'm not able to solve it. Then the codes will go with the error. Thank you.

import math

class Bhaskara:

    def delta(self, a, b, c):
        return b ** 2 - 4 * a * c

    def calcula_raizes(self, a, b, c):
        d = self.delta(a, b, c)
        if d == 0:
            raiz1 = (-b + math.sqrt(d)) / (2 * a)
            return 1, raiz1
        else:
            if d < 0:
                return 0
            else:
                raiz1 = (-b + math.sqrt(d)) / (2 * a)
                raiz2 = (-b - math.sqrt(d)) / (2 * a)
                return 2, raiz1, raiz2

import Bhaskara

import pytest

class Test_Bhaskara:

    @pytest.fixture
    def b(self):
        return Bhaskara.Bhaskara()

    @pytest.mark.parametrize("entrada, saida", [
            ((1, 0, 0), (1, 0,)),
            ((1, -5, 6), (2, 3, 2)),
            ((10, 10, 10), (0,)),
            ((10, 20, 10), (1, -1))
        ])

    def testa_bhaskara(self, entrada, saida):
        b = Bhaskara()
        assert b.calcula_raizes(entrada) == saida

Pytest output

___ Test_Bhaskara.testa_bhaskara[entrada3-saida3] ___

self = <Test_Bhaskara.Test_Bhaskara instance at 0x7f1ea0453680>
entrada = (10, 20, 10), saida = (1, -1)

@pytest.mark.parametrize("entrada, saida", [
            [(1, 0, 0,), (1, 0,)],
            [(1, -5, 6,), (2, 3, 2,)],
            [(10, 10, 10,), (0,)],
            [(10, 20, 10,), (1, -1,)]
        ])

def testa_bhaskara(self, entrada, saida):
    b = Bhaskara()
    TypeError: 'module' object is not callable

Test_Bhaskara.py:14: TypeError
========= 4 failed in 0.04 seconds =========
    
asked by anonymous 20.11.2017 / 20:37

1 answer

0

Use:

from Bhaskara import Bhaskara

Then he will load the "Bhaskara" class into "Bhaskara.py".

Incidentally, the calcula_raizes () method is wrong because it expects three numeric values and you are sending a tuple to it. Not to mess with what you've already ridden for the tests, try something like this:

def calcula_raizes(self, valores):
    (a, b, c) = valores
    d = self.delta(a, b, c)
    ...

What you should resolve.

    
24.03.2018 / 04:10