Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix test_exapp #288

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open

Fix test_exapp #288

wants to merge 1 commit into from

Conversation

jiasli
Copy link
Member

@jiasli jiasli commented Jul 16, 2024

Fix #287

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The .py file extension is necessary, otherwise pytest won't collect this file at all.

> pytest examples\test_exapp
================================================= test session starts =================================================
platform win32 -- Python 3.11.9, pytest-8.2.2, pluggy-1.5.0
rootdir: D:\cli\knack
plugins: forked-1.6.0, xdist-3.6.1
collected 0 items

================================================ no tests ran in 0.02s ================================================
ERROR: not found: D:\cli\knack\examples\test_exapp
(no match in any of [<Dir examples>])

That's why the error is not exposed in CI.

@@ -31,9 +31,9 @@ def hello_command_handler(myarg=None, abc=None):
class MyCommandsLoader(CLICommandsLoader):

def load_command_table(self, args):
with CommandGroup(self, 'hello', '__main__#{}') as g:
with CommandGroup(self, 'hello', '{}#{{}}'.format(__name__)) as g:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

__main__ denotes this file only when this file is directly invoked by python.

When invoked from pytest, __main__ is actually D:\cli\py311\Scripts\pytest.exe\__main__.py. This can be verified by adding import __main__; print(__main__):

> pytest examples\test_exapp.py -s
================================================= test session starts =================================================
platform win32 -- Python 3.11.9, pytest-8.2.2, pluggy-1.5.0
rootdir: D:\cli\knack
plugins: forked-1.6.0, xdist-3.6.1
collecting ... <module '__main__' from 'D:\\cli\\py311\\Scripts\\pytest.exe\\__main__.py'>

Comment on lines +84 to +85
def __init__(self, method_name, filter_headers=None):
super().__init__(method_name)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#287 (comment) explains why positional argument cli is removed.

Comment on lines +64 to +66
def setUp(self):
super().setUp()
self.cli = mycli
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initializing self.cli in setUp adheres to the "do heavy work in setUp" principle: Azure/azure-cli#28849

@RyoYang
Copy link

RyoYang commented Aug 21, 2024

Do we have an ETA to merge this PR? @jiasli

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants