Python unittest files in subdirectory causing import failures in parent -


i'm adding unit , integration tests existing oss library, , imports failing unexpectedly when add subdirectory of tests. i've boiled down following:

. ├── driver.py ├── lib │   ├── __init__.py │   ├── a.py │   └── b.py └── test     ├── __init__.py     └── test_driver.py 

my driver.py imports lib classes , b:

$ cat driver.py lib import a, b  def do_it(): pass  if __name__ == '__main__': do_it() 

and following integration test works:

$ cat test/test_driver.py import unittest, driver lib import  # import required tests  class t(unittest.testcase):   def test_a(self): pass 

running:

$ python -m unittest discover  => ran 1 test in 0.000s; ok 

i'm trying add tests library files:

... └── test     ├── __init__.py     ├── lib  <== added dir , content     │   ├── __init__.py     │   └── test_b.py     └── test_driver.py 

test_b.py contains following:

import unittest lib import b class t2(unittest.testcase):     def test_b(self): pass 

with added, test_driver.py starts failing:

error: test.test_driver (unittest.loader.moduleimportfailure) importerror: failed import test module: test.test_driver ... importerror: cannot import name 

can explain why adding subdirectory of tests impact tests in parent? , way work around this?


update: i've got solution, still don't understand why. solution move integration tests separate subfolder:

├── test │   ├── __init__.py   <= still needed package discovery │   ├── integration │   │   ├── __init__.py │   │   └── test_driver.py  <= moved top level │   └── lib │       ├── __init__.py │       └── test_b.py 

and tests ran correctly. can explain what's going on behind-the-scenes? link or doc suggestions appreciated. thanks, jz


Comments

Popular posts from this blog

html - Styling progress bar with inline style -

java - Oracle Sql developer error: could not install some modules -

How to use autoclose brackets in Jupyter notebook? -