1

for ease of organization and additional testing, we need to split out a section of code in a project from a single file into a directory of files. basically the project is large, this section needs some additional isolated tests, and this is the best way - workflow wise and without gutting a ton of code - to handle our needs.

the directory now looks like this:

  • __init__.py
  • core.py
  • api.py
  • misc.py
  • tests.py ( unittest.TestCase examples )

the application just deals with the methods from api.py ; however the other files interface with one another.

this is where i'm having a bit of an issue / second-guessing myself.

i'd usually do something like this to be explicit in my imports :

from .api import *

that works fine in the application, however when on the commandline to run local tests:

$ python tests.py

Python doesn't like the import.

This seems to be because I'm wanting to accomplish an anti-pattern ( at least according to Guido van Rossum - https://stackoverflow.com/a/6466139/442650 )

I haven't been able to find any better docs or recommendations on how to better set this up, aside from treating this part of the application as an external module -- which is not an option. that would create a ton of work on our build/deploy script.

The only other thing I can think of, is an application structure like the following, where i manage the package outside the application and then symlink back into it :

* /src/application_parts
* /src/application_parts/mymodule
* /src/application_parts/mymodule/tests.py
* /src/application_parts/mymodule/lib
* /src/application
* /src/application/mymodule ( symlinks to /src/application_parts/mymodule/lib )

this looks like something even worse though.

Community
  • 1
  • 1
Jonathan Vanasco
  • 15,111
  • 10
  • 48
  • 72

0 Answers0