temperlang / temper

3 stars 0 forks source link

Stop importing tests in python library inits #76

Closed tjpalmer closed 8 months ago

tjpalmer commented 9 months ago

Example problem:

~/projects/temper/cli/src/test/resources/testing/multi$ temper repl -b py
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/tom/projects/temper/cli/src/test/resources/testing/multi/temper.out/py/a/py_a/__init__.py", line 1, in <module>
    from py_a.a import *
  File "/home/tom/projects/temper/cli/src/test/resources/testing/multi/temper.out/py/a/py_a/a.py", line 2, in <module>
    from b.b import bad as bad__0
  File "/home/tom/projects/temper/cli/src/test/resources/testing/multi/temper.out/py/b/b/__init__.py", line 3, in <module>
    from tests.test_test import *
  File "/home/tom/projects/temper/cli/src/test/resources/testing/multi/temper.out/py/test-me/tests/test_test.py", line 3, in <module>
    from test_me.test import eq__2
  File "/home/tom/projects/temper/cli/src/test/resources/testing/multi/temper.out/py/test-me/test_me/__init__.py", line 3, in <module>
    from test_me.test import *
  File "/home/tom/projects/temper/cli/src/test/resources/testing/multi/temper.out/py/test-me/test_me/test.py", line 3, in <module>
    from py_a.a import bad_message as badMessage__4
ImportError: cannot import name 'bad_message' from partially initialized module 'py_a.a' (most likely due to a circular import) (/home/tom/projects/temper/cli/src/test/resources/testing/multi/temper.out/py/a/py_a/a.py)
>>>

Trying to import from different test roots is causing trouble here, but really we shouldn't be importing from the tests at all in the main code.

tjpalmer commented 9 months ago

On a different system, I'm not seeing the same circular import complaint, but I do still see tests being imported, which is still bad. Maybe slightly different build results can cause the circular import or not.

tjpalmer commented 9 months ago

I might defer working this until getting to handling dir modules.

tjpalmer commented 9 months ago

Working dir modules, and it seems like once we switch over, the other "import everything" logic will go unused, so this issue also likely will go away.