Merge "Add flag to not add top-level modules to PYTHONPATH"
This commit is contained in:
9
python/tests/top_level_dirs/Android.bp
Normal file
9
python/tests/top_level_dirs/Android.bp
Normal file
@@ -0,0 +1,9 @@
|
||||
python_test_host {
|
||||
name: "py_dont_add_top_level_dirs_test",
|
||||
main: "main.py",
|
||||
srcs: [
|
||||
"main.py",
|
||||
"mypkg/mymodule.py",
|
||||
],
|
||||
dont_add_top_level_directories_to_path: true,
|
||||
}
|
17
python/tests/top_level_dirs/main.py
Normal file
17
python/tests/top_level_dirs/main.py
Normal file
@@ -0,0 +1,17 @@
|
||||
import unittest
|
||||
import sys
|
||||
|
||||
print(sys.path, file=sys.stderr)
|
||||
|
||||
class TestProtoWithPkgPath(unittest.TestCase):
|
||||
|
||||
def test_cant_import_mymodule_directly(self):
|
||||
with self.assertRaises(ImportError):
|
||||
import mymodule
|
||||
|
||||
def test_can_import_mymodule_by_parent_package(self):
|
||||
import mypkg.mymodule
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
0
python/tests/top_level_dirs/mypkg/mymodule.py
Normal file
0
python/tests/top_level_dirs/mypkg/mymodule.py
Normal file
Reference in New Issue
Block a user