test/py: support pytest 6
PATCH 1/1 test/py: support pytest 6
Two changes are needed to support pytest 6:
1) The main entry point no longer allows command-line arguments to be supplied. Instead, we must modify sys.argv before calling the entry point. pytest 5.1.2 (from the current requirements.txt) supports either modifying sys.argv, or passing arguments, so is compatible with this change.
2) The implementation of pytest_runtest_protocol() must call pytest_runtest_logstart() and pytest_runtest_logfinish(). This appears to be necessary even in pytest 5.1.2 judging by the default version of pytest_runtest_protocol(), but evidently some form of code reorganization in pytest only made this have a practical effect in the newer version. I'd previously been under the impression that 100% of the required work of pytest_runtest_protocol() was handled by the fact it called runtestprotocol() as its implementation. However, it appears that custom implementations do need to do a little more than this.
--- test/py/conftest.py | 5 ++++- test/py/test.py | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-)
test/py/conftest.py +4 -1
@@ -554,7 +554,10 @@ def pytest_runtest_protocol(item, nextitem): """ log.get_and_reset_warning() + ihook = item.ihook + ihook.pytest_runtest_logstart(nodeid=item.nodeid, location=item.location) reports = runtestprotocol(item, nextitem=nextitem) + ihook.pytest_runtest_logfinish(nodeid=item.nodeid, location=item.location) was_warning = log.get_and_reset_warning() # In pytest 3, runtestprotocol() may not call pytest_runtest_setup() if
@@ -623,4 +626,4 @@ def pytest_runtest_protocol(item, nextitem): if failure_cleanup: console.cleanup_spawn() - return reports + return True # reports
test/py/test.py +2 -2
@@ -14,7 +14,7 @@ from pkg_resources import load_entry_point # argv; py.test test_directory_name user-supplied-arguments args = [os.path.dirname(__file__) + '/tests'] -args.extend(sys.argv) +sys.argv[1:1] = args if __name__ == '__main__': - sys.exit(load_entry_point('pytest', 'console_scripts', 'pytest')(args)) + sys.exit(load_entry_point('pytest', 'console_scripts', 'pytest')())
Signature · 1 line
2.25.1
PATCH 1/1 test/py: support pytest 6
Am 30. Januar 2021 22:05:44 MEZ schrieb Stephen Warren <[email protected]>:
Quoted 62 lines
Two changes are needed to support pytest 6:
1) The main entry point no longer allows command-line arguments to be supplied. Instead, we must modify sys.argv before calling the entry point. pytest 5.1.2 (from the current requirements.txt) supports either modifying sys.argv, or passing arguments, so is compatible with this change.
2) The implementation of
pytest_runtest_protocol()must callpytest_runtest_logstart()andpytest_runtest_logfinish(). This appears to
be necessary even in pytest 5.1.2 judging by the default version ofpytest_runtest_protocol(), but evidently some form of code reorganization in pytest only made this have a practical effect in the newer version. I'd previously been under the impression that 100% of the
required work ofpytest_runtest_protocol()was handled by the fact it calledruntestprotocol()as its implementation. However, it appears that
custom implementations do need to do a little more than this.Signed-off-by Stephen Warren <[email protected]>---
test/py/conftest.py| 5 ++++-test/py/test.py| 4 ++--2 files changed, 6 insertions(+), 3 deletions(-)test/py/conftest.py +3
-0@@ -554,7 +554,10 @@ def pytest_runtest_protocol(item, nextitem): """ log.get_and_reset_warning() + ihook = item.ihook + ihook.pytest_runtest_logstart(nodeid=item.nodeid, location=item.location) reports = runtestprotocol(item, nextitem=nextitem) + ihook.pytest_runtest_logfinish(nodeid=item.nodeid, location=item.location) was_warning = log.get_and_reset_warning()# In pytest 3,
runtestprotocol()may not callpytest_runtest_setup()iftest/py/conftest.py +1
-1@@ -623,4 +626,4 @@ def pytest_runtest_protocol(item, nextitem): if failure_cleanup: console.cleanup_spawn() - return reports + return True # reportstest/py/test.py +0
-0@@ -14,7 +14,7 @@ from pkg_resources import load_entry_point # argv; py.test test_directory_name user-supplied-argumentsargs = [
os.path.dirname(__file__)+ '/tests']test/py/test.py +1
-1-args.extend(sys.argv) +sys.argv[1:1] = args
Quoted 5 lines
if
__name__== '__main__':
- sys.exit(load_entry_point('pytest', 'console_scripts',
'pytest')(args))
+ sys.exit(load_entry_point('pytest', 'console_scripts',
'pytest')())
Your patch is not based on origin master. This line was already corrected. We should not use console_scripts. Cf.
https://github.com/trini/u-boot/blob/master/test/py/test.py#L20
Best regards
Heinrich
PATCH 1/1 test/py: support pytest 6
Quoted 71 lines · Heinrich Schuchardt
Am 30. Januar 2021 22:05:44 MEZ schrieb Stephen Warren <[email protected]>:
Quoted 62 lines
Two changes are needed to support pytest 6:
1) The main entry point no longer allows command-line arguments to be supplied. Instead, we must modify sys.argv before calling the entry point. pytest 5.1.2 (from the current requirements.txt) supports either modifying sys.argv, or passing arguments, so is compatible with this change.
2) The implementation of
pytest_runtest_protocol()must callpytest_runtest_logstart()andpytest_runtest_logfinish(). This appears to
be necessary even in pytest 5.1.2 judging by the default version ofpytest_runtest_protocol(), but evidently some form of code reorganization in pytest only made this have a practical effect in the newer version. I'd previously been under the impression that 100% of the
required work ofpytest_runtest_protocol()was handled by the fact it calledruntestprotocol()as its implementation. However, it appears that
custom implementations do need to do a little more than this.Signed-off-by Stephen Warren <[email protected]>---
test/py/conftest.py| 5 ++++-test/py/test.py| 4 ++--2 files changed, 6 insertions(+), 3 deletions(-)test/py/conftest.py +3
-0@@ -554,7 +554,10 @@ def pytest_runtest_protocol(item, nextitem): """ log.get_and_reset_warning() + ihook = item.ihook + ihook.pytest_runtest_logstart(nodeid=item.nodeid, location=item.location) reports = runtestprotocol(item, nextitem=nextitem) + ihook.pytest_runtest_logfinish(nodeid=item.nodeid, location=item.location) was_warning = log.get_and_reset_warning()# In pytest 3,
runtestprotocol()may not callpytest_runtest_setup()iftest/py/conftest.py +1
-1@@ -623,4 +626,4 @@ def pytest_runtest_protocol(item, nextitem): if failure_cleanup: console.cleanup_spawn() - return reports + return True # reportstest/py/test.py +0
-0@@ -14,7 +14,7 @@ from pkg_resources import load_entry_point # argv; py.test test_directory_name user-supplied-argumentsargs = [
os.path.dirname(__file__)+ '/tests']test/py/test.py +1
-1-args.extend(sys.argv) +sys.argv[1:1] = argsQuoted 5 lines
if
__name__== '__main__':
- sys.exit(load_entry_point('pytest', 'console_scripts',
'pytest')(args))
+ sys.exit(load_entry_point('pytest', 'console_scripts',
'pytest')())Your patch is not based on origin master. This line was already corrected. We should not use
console_scripts. Cf.
I tested with only the changes to test/py/conftest.py from your patch applied and this fixes the problem on Pytest 6.
Thanks for you swift response.
Best regards
Heinrich