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:28:56 +0100 |
commit | fd1d2c6dc73e084918b4290214652bcff9b99261 (patch) | |
tree | 8ccec2318f0d0488c8a07410744608cca374787b /bitbake/lib/bb/tests | |
parent | 8b0fc4850dc31bb7e7be0001414468b1d3f80846 (diff) | |
download | poky-fd1d2c6dc73e084918b4290214652bcff9b99261.tar.gz |
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>
Diffstat (limited to 'bitbake/lib/bb/tests')
-rw-r--r-- | bitbake/lib/bb/tests/fetch.py | 6 | ||||
-rw-r--r-- | bitbake/lib/bb/tests/parse.py | 16 |
2 files changed, 12 insertions, 10 deletions
diff --git a/bitbake/lib/bb/tests/fetch.py b/bitbake/lib/bb/tests/fetch.py index 8ca7e6c155..20593764fd 100644 --- a/bitbake/lib/bb/tests/fetch.py +++ b/bitbake/lib/bb/tests/fetch.py | |||
@@ -3183,7 +3183,7 @@ class FetchPremirroronlyBrokenTarball(FetcherTest): | |||
3183 | import sys | 3183 | import sys |
3184 | self.d.setVar("SRCREV", "0"*40) | 3184 | self.d.setVar("SRCREV", "0"*40) |
3185 | fetcher = bb.fetch.Fetch([self.recipe_url], self.d) | 3185 | fetcher = bb.fetch.Fetch([self.recipe_url], self.d) |
3186 | with self.assertRaises(bb.fetch2.FetchError): | 3186 | with self.assertRaises(bb.fetch2.FetchError), self.assertLogs() as logs: |
3187 | fetcher.download() | 3187 | fetcher.download() |
3188 | stdout = sys.stdout.getvalue() | 3188 | output = "".join(logs.output) |
3189 | self.assertFalse(" not a git repository (or any parent up to mount point /)" in stdout) | 3189 | self.assertFalse(" not a git repository (or any parent up to mount point /)" in output) |
diff --git a/bitbake/lib/bb/tests/parse.py b/bitbake/lib/bb/tests/parse.py index a3165d95bd..304bbbe222 100644 --- a/bitbake/lib/bb/tests/parse.py +++ b/bitbake/lib/bb/tests/parse.py | |||
@@ -186,14 +186,16 @@ deltask ${EMPTYVAR} | |||
186 | """ | 186 | """ |
187 | def test_parse_addtask_deltask(self): | 187 | def test_parse_addtask_deltask(self): |
188 | import sys | 188 | import sys |
189 | f = self.parsehelper(self.addtask_deltask) | ||
190 | d = bb.parse.handle(f.name, self.d)[''] | ||
191 | 189 | ||
192 | stdout = sys.stdout.getvalue() | 190 | with self.assertLogs() as logs: |
193 | self.assertTrue("addtask contained multiple 'before' keywords" in stdout) | 191 | f = self.parsehelper(self.addtask_deltask) |
194 | self.assertTrue("addtask contained multiple 'after' keywords" in stdout) | 192 | d = bb.parse.handle(f.name, self.d)[''] |
195 | self.assertTrue('addtask ignored: " do_patch"' in stdout) | 193 | |
196 | #self.assertTrue('dependent task do_foo for do_patch does not exist' in stdout) | 194 | output = "".join(logs.output) |
195 | self.assertTrue("addtask contained multiple 'before' keywords" in output) | ||
196 | self.assertTrue("addtask contained multiple 'after' keywords" in output) | ||
197 | self.assertTrue('addtask ignored: " do_patch"' in output) | ||
198 | #self.assertTrue('dependent task do_foo for do_patch does not exist' in output) | ||
197 | 199 | ||
198 | broken_multiline_comment = """ | 200 | broken_multiline_comment = """ |
199 | # First line of comment \\ | 201 | # First line of comment \\ |