I'm using jetbrains academy with pycharm and I'm trying to build a course with automatic checking with unittests in python. Here what I get when creating a default task of type "edu":
When I look at the default test_task.py (I didn't change a single line), the problem is already obvious:
import unittest
from task import summe
# todo: replace this with an actual test
class TestCase(unittest.TestCase):
def test_add(self):
self.assertEqual(summe(1, 2), 3, msg="adds 1 + 2 to equal 3")
Line 3 doesn't work because task is not visible from test_task.py. I can't/don't want to change the structure because of the course structure. What can I do? And why is there no documentation from Jetbrains?
Edit: And why would Jetbrains give us a template which is not working, am I missing something?
Thx for any help Reto
I already tried relative imports (from .. import task), obviously don't work. I also tried some path-meddling with sys.path.append('../task1'), no results. It's amazing something seemingly that simple is so complicated...
I think you are not able to get files from higher directories. You can use test_task.py in task.py by:
But I think it's not possible to do it the other way around. What's possible tho, is using the sys and os module to create a directory where your task.py is stored and import it like this. This website explains it:
https://favtutor.com/blogs/import-from-parent-directory-python#:~:text=Conclusion,Python%20with%20many%20subdirectories%20simple.
I hope this helps!