diff options
author | Peter Hoyes <Peter.Hoyes@arm.com> | 2023-06-16 13:36:50 +0100 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2023-06-27 15:27:02 +0100 |
commit | 2d28caa01bab9540d2bbaf713ae3e5c563d003f5 (patch) | |
tree | 7aa1675d7046b8c95fd5681e3da23af851bc3a0c | |
parent | 0c7079d0609a13713b890a9675abd9fba032f199 (diff) | |
download | bitbake-contrib-2d28caa01bab9540d2bbaf713ae3e5c563d003f5.tar.gz |
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.
Signed-off-by: Peter Hoyes <Peter.Hoyes@arm.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r-- | lib/bb/tests/fetch.py | 6 | ||||
-rw-r--r-- | lib/bb/tests/parse.py | 16 |
2 files changed, 12 insertions, 10 deletions
diff --git a/lib/bb/tests/fetch.py b/lib/bb/tests/fetch.py index 8ca7e6c15..20593764f 100644 --- a/lib/bb/tests/fetch.py +++ b/lib/bb/tests/fetch.py @@ -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) diff --git a/lib/bb/tests/parse.py b/lib/bb/tests/parse.py index a3165d95b..304bbbe22 100644 --- a/lib/bb/tests/parse.py +++ b/lib/bb/tests/parse.py @@ -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 \\ |