Python unittest

0

Witam, mam problem z wykonaniem unittestu na zrobionym przeze mnie skrypcie. Otóż gdy wykonałam unittest dla obu funkcji to na zmianę wyświetla się wykonanie obu lub jednego testu. Kombinowałam na różne sposoby, ale nic to nie dało. Bardzo proszę o pomoc.

def GiveGeomSeqElement(a1=2, factor=2, index=2):
    # value of 64 elements of a geometric string with the first element 1 and a factor of 2
    value = a1 * pow(factor, index - 1)
    print("I")
    return value


def GiveGeomSeqElementII(a1=3, factor=2, maxindex=10):

    for i in range(1, maxindex):
        an = GiveGeomSeqElement(a1=a1, factor=factor, index=i)
        #print("element", i, "value:", an)
        print("II")
        return True


if __name__ == "__main__":
    GiveGeomSeqElement()
    GiveGeomSeqElementII()
import main
import unittest


class testMain(unittest.TestCase):

    def test_GiveGeomSeqElement(self):

        self.assertNotEqual(8, main.GiveGeomSeqElement(3, 2, 10))
        self.assertEqual(32768, main.GiveGeomSeqElement(1, 2, 16))
        self.assertEqual(-32, main.GiveGeomSeqElement(1, -2, 6))
        self.assertNotEqual(1, main.GiveGeomSeqElement(1, 2, 0))
        self.assertEqual(0, main.GiveGeomSeqElement(1, 0, 2))

    def test_GiveGeomSeqElementII(self):

        self.assertTrue(main.GiveGeomSeqElementII())


if __name__ == "__main__":
    unittest.main()
0
  1. Stosuj snake_case zamiast camelCase
  2. Plik z funkcjami GiveGeomSeqElement i GiveGeomSeqElementII powinien nazywać się main.py w Twoim przykładzie, zakładając że plik z testami i ten plik znajdują się w tym samym katalogu.
2

w funkcji

GiveGeomSeqElementII

wywolujesz

GiveGeomSeqElement

dlatego printuje sie na zmiane I/II

1 użytkowników online, w tym zalogowanych: 0, gości: 1