Skip to content

Commit c87b3f0

Browse files
petrus-vyvaucher
authored andcommitted
[FIX] _find_manifest_path when no manifest found
This happens if the test module is less than 5 directories deep from root.
1 parent c68bc3d commit c87b3f0

File tree

3 files changed

+44
-3
lines changed

3 files changed

+44
-3
lines changed

pytest_odoo.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -233,10 +233,12 @@ def _find_manifest_path(collection_path: Path) -> Path:
233233
"""Try to locate an Odoo manifest file in the collection path."""
234234
# check if collection_path is an addon directory
235235
path = collection_path
236-
level = 0
237-
while level < 5 and not (path.parent / "__manifest__.py").is_file():
236+
for _ in range(0, 5):
237+
if (path.parent / "__manifest__.py").is_file():
238+
break
238239
path = path.parent
239-
level += 1
240+
else:
241+
return None
240242
return path.parent / "__manifest__.py"
241243

242244

tests/__init__.py

Whitespace-only changes.

tests/test_pytest_odoo.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
from unittest import TestCase
2+
import tempfile
3+
from contextlib import contextmanager
4+
from pytest_odoo import _find_manifest_path
5+
from pathlib import Path
6+
7+
class TestPytestOdoo(TestCase):
8+
9+
@contextmanager
10+
def fake_module(self):
11+
directory = tempfile.TemporaryDirectory()
12+
try:
13+
module_path = Path(directory.name)
14+
manifest_path = module_path / "__manifest__.py"
15+
manifest_path.touch()
16+
test_path = module_path / "tests" / "test_module.py"
17+
test_path.parent.mkdir(parents=True, exist_ok=True)
18+
test_path.touch()
19+
yield (module_path, manifest_path, test_path,)
20+
finally:
21+
directory.cleanup()
22+
23+
24+
def test_find_manifest_path_less_than_5_directories(self):
25+
self.assertIsNone(_find_manifest_path(Path("/some/path")))
26+
27+
def test_find_manifest_path_from_test_module(self):
28+
with self.fake_module() as (_, manifest_path, test_path):
29+
self.assertEqual(_find_manifest_path(test_path), manifest_path)
30+
31+
def test_find_manifest_path_from_itself(self):
32+
with self.fake_module() as (_, manifest_path, _):
33+
self.assertEqual(_find_manifest_path(manifest_path), manifest_path)
34+
35+
def test_find_manifest_path_from_brother(self):
36+
with self.fake_module() as (module_path, manifest_path, _):
37+
test = module_path / "test_something.py"
38+
test.touch()
39+
self.assertEqual(_find_manifest_path(test), manifest_path)

0 commit comments

Comments
 (0)