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

Broken examples/test_exapp: TypeError: ScenarioTest.__init__() missing 1 required positional argument: 'method_name' #287

Open
jiasli opened this issue Jul 16, 2024 · 1 comment · May be fixed by #288

Comments

@jiasli
Copy link
Member

jiasli commented Jul 16, 2024

First of all, examples/test_exapp cannot be directly executed by pytest.

> 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>])

After renaming it to test_exapp.py. pytest fails with

> pytest examples\test_exapp.py
================================================= 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 3 items / 1 error

======================================================= ERRORS ========================================================
_______________________________________ ERROR collecting examples/test_exapp.py _______________________________________
..\py311\Lib\site-packages\_pytest\runner.py:341: in from_call
    result: Optional[TResult] = func()
..\py311\Lib\site-packages\_pytest\runner.py:389: in collect
    return list(collector.collect())
..\py311\Lib\site-packages\_pytest\unittest.py:90: in collect
    self.session._fixturemanager.parsefactories(self.newinstance(), self.nodeid)
..\py311\Lib\site-packages\_pytest\unittest.py:75: in newinstance
    return self.obj("runTest")
E   TypeError: ScenarioTest.__init__() missing 1 required positional argument: 'method_name'
=============================================== short test summary info ===============================================
ERROR examples/test_exapp.py::ScenarioTest - TypeError: ScenarioTest.__init__() missing 1 required positional argument: 'method_name'
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
================================================== 1 error in 0.96s ===================================================
@jiasli jiasli changed the title Broken examples/test_exapp Broken examples/test_exapp: TypeError: ScenarioTest.__init__() missing 1 required positional argument: 'method_name' Jul 16, 2024
@jiasli
Copy link
Member Author

jiasli commented Jul 16, 2024

I think the reason for the TypeError: ScenarioTest.__init__() missing 1 required positional argument: 'method_name' error is related to pytest-dev/pytest#12289.

As ScenarioTest is imported into examples/test_exapp:

from knack.testsdk import ScenarioTest, JMESPathCheck

pytest treats ScenarioTest as a normal test class and calls its __init__ with method_name="runTest". However, knack.testsdk.base.ScenarioTest.__init__ requires 2 positional arguments:

class ScenarioTest(IntegrationTestBase): # pylint: disable=too-many-instance-attributes
def __init__(self, cli, method_name, filter_headers=None):

resulting in the error.

On the other hand, azure.cli.testsdk.base.ScenarioTest only has 1 positional argument:

https://github.com/Azure/azure-cli/blob/2750c65ea77638ecf699243555a5f2f7a1314ed4/src/azure-cli-testsdk/azure/cli/testsdk/base.py#L82-L85

class ScenarioTest(ReplayableTest, CheckerMixin, unittest.TestCase):
    def __init__(self, method_name, config_file=None, recording_name=None,
                 recording_processors=None, replay_processors=None, recording_patches=None, replay_patches=None,
                 random_config_dir=False):

thus not having this issue.

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

Successfully merging a pull request may close this issue.

1 participant