bitbake: bitbake: tests: Use assertLogs to test logging output

By default, pytest captures all stdout and exposes it using its built-in
fixtures (capsys, caplog etc), so stdout does not support getvalue().

To support running tests using both unittest and pytest, use assertLogs
to capture logging and assert on the log output instead.

(Bitbake rev: 2d28caa01bab9540d2bbaf713ae3e5c563d003f5)

Signed-off-by: Peter Hoyes <Peter.Hoyes@arm.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Peter Hoyes
2023-06-16 13:36:50 +01:00
committed by Richard Purdie
parent 8b0fc4850d
commit fd1d2c6dc7
2 changed files with 12 additions and 10 deletions

View File

@@ -3183,7 +3183,7 @@ class FetchPremirroronlyBrokenTarball(FetcherTest):
import sys
self.d.setVar("SRCREV", "0"*40)
fetcher = bb.fetch.Fetch([self.recipe_url], self.d)
with self.assertRaises(bb.fetch2.FetchError):
with self.assertRaises(bb.fetch2.FetchError), self.assertLogs() as logs:
fetcher.download()
stdout = sys.stdout.getvalue()
self.assertFalse(" not a git repository (or any parent up to mount point /)" in stdout)
output = "".join(logs.output)
self.assertFalse(" not a git repository (or any parent up to mount point /)" in output)

View File

@@ -186,14 +186,16 @@ deltask ${EMPTYVAR}
"""
def test_parse_addtask_deltask(self):
import sys
f = self.parsehelper(self.addtask_deltask)
d = bb.parse.handle(f.name, self.d)['']
stdout = sys.stdout.getvalue()
self.assertTrue("addtask contained multiple 'before' keywords" in stdout)
self.assertTrue("addtask contained multiple 'after' keywords" in stdout)
self.assertTrue('addtask ignored: " do_patch"' in stdout)
#self.assertTrue('dependent task do_foo for do_patch does not exist' in stdout)
with self.assertLogs() as logs:
f = self.parsehelper(self.addtask_deltask)
d = bb.parse.handle(f.name, self.d)['']
output = "".join(logs.output)
self.assertTrue("addtask contained multiple 'before' keywords" in output)
self.assertTrue("addtask contained multiple 'after' keywords" in output)
self.assertTrue('addtask ignored: " do_patch"' in output)
#self.assertTrue('dependent task do_foo for do_patch does not exist' in output)
broken_multiline_comment = """
# First line of comment \\