[Tutor] When are "__init__.py" files needed and not needed in a project?

boB Stepp robertvstepp at gmail.com
Sat Oct 20 17:52:03 EDT 2018

On Sat, Oct 20, 2018 at 1:36 PM Peter Otten <__peter__ at web.de> wrote:
> boB Stepp wrote:
> > Linux Mint 19 Cinnamon, Python 3.6.6
> > I was expecting this error and will shortly correct it.  So my
> > question remains, when are "__init__.py" files needed and when are
> > they not?
> I am struggling with the differences between the two types of packages
> myself, so my first guess was that you accidentally found out that test
> discovery doesn't work for namespace packages. However
> https://docs.python.org/dev/library/unittest.html#test-discovery
> expicitly states
> """
> Changed in version 3.4: Test discovery supports namespace packages.
> """
> Perhaps you should file a bug report.

I just waded through PEP 420 describing "implicit namespace packages".
I think I have a cursory understanding now, but not enough to feel
confidant to file a bug report.  It *seems* that with my project
structure below (Note the slight correction.) if I initiate test
discovery in the top level directory (The one holding main.py.) and
have no __init__.py files anywhere, that my initial effort should have
run the one test with the resulting error instead of running 0 tests.
Can anything reading this duplicate my issue?  If yes, then I will
endeavour to file a bug report.  But otherwise, I would suspect
something screwy that I have done and am currently unaware of what it
may be.

> > In case it helps, my current project structure is:
> >
> > ~/Projects
> >     data/
> >     docs/
> >     tests/
> >     .git/
> >     main.py
> >     .gitignore

Just noticed that I mistyped the top level of my project structure.
It should be:


More information about the Tutor mailing list