File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change 1+ import runpy
2+ import sys
3+ from pathlib import Path
4+
5+ import pytest
16from conftest import cmd , cmd_subprocess
27
38import west .version
@@ -21,3 +26,25 @@ def test_main():
2126
2227 # output must be same in both cases
2328 assert output_subprocess .rstrip () == output_directly .rstrip ()
29+
30+
31+ def test_module_run (tmp_path , monkeypatch ):
32+ actual_path = ['initial-path' ]
33+
34+ # mock sys.argv and sys.path
35+ monkeypatch .setattr (sys , 'path' , actual_path )
36+ monkeypatch .setattr (sys , 'argv' , ['west' , '--version' ])
37+
38+ # ensure that west.app.main is freshly loaded
39+ sys .modules .pop ('west.app.main' , None )
40+
41+ # run west.app.main as module
42+ with pytest .raises (SystemExit ) as exit_info :
43+ runpy .run_module ('west.app.main' , run_name = '__main__' )
44+
45+ # check that exit code is 0
46+ assert exit_info .value .code == 0
47+
48+ # check that that the sys.path was correctly inserted
49+ expected_path = Path (__file__ ).parents [1 ] / 'src'
50+ assert actual_path == [f'{ expected_path } ' , 'initial-path' ]
You can’t perform that action at this time.
0 commit comments