jeudi 1 avril 2021

Error during import a module running tests

I want to run unit tests using unittest module, this is the file organization of my project:

frac
├── frac.py
├── __init__.py
└── test
    └── run_tests.py

The code inside run_tests.py is:

import unittest
from frac import Fraction

class RunFractionTests(unittest.TestCase):
    def multiplications(self):
        a = Fraction(1, 2)
        b = Fraction(1, 2)
        self.assertEqual(a * b, Fraction(1, 4))

The problem is, when i run run_tests.py with python run_tests.py, i get an error saying that the module frac was not found, this is the error message:

Traceback (most recent call last):
  File "/home/maurothecreator/Área de Trabalho/Projects/HighMath/frac/test/run_tests.py", line 2, in <module>
    from frac import Fraction
ModuleNotFoundError: No module named 'frac'

Am i importing this in the wrong way, if so, how can i fix this?

Aucun commentaire:

Enregistrer un commentaire