test: fix running tests as non-root system user#626
Open
bdrung wants to merge 1 commit into
Open
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #626 +/- ##
=======================================
Coverage 84.37% 84.38%
=======================================
Files 106 106
Lines 21035 21039 +4
Branches 3220 3221 +1
=======================================
+ Hits 17749 17753 +4
+ Misses 2803 2802 -1
- Partials 483 484 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
86f92cf to
90d7e99
Compare
sbuild with the unshare backend will run as system user (but not root).
This causes these two tests to fail:
```
=================================== FAILURES ===================================
_______________ TestApportCheckreports.test_has_no_system_report _______________
self = <tests.integration.test_apport_checkreports.TestApportCheckreports testMethod=test_has_no_system_report>
def test_has_no_system_report(self) -> None:
self._write_report("_bin_sleep.1000.crash")
> self._call(args=["--system"], expected_returncode=1)
tests/integration/test_apport_checkreports.py:68:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
tests/integration/test_apport_checkreports.py:53: in _call
self.assertEqual(process.returncode, expected_returncode)
E AssertionError: 0 != 1
__________________________ T.test_get_system_reports ___________________________
self = <tests.integration.test_fileutils.T testMethod=test_get_system_reports>
def test_get_system_reports(self) -> None:
"""get_all_system_reports() and get_new_system_reports()"""
self.assertEqual(apport.fileutils.get_all_reports(), [])
self.assertEqual(apport.fileutils.get_all_system_reports(), [])
if os.getuid() == 0:
tr = self._create_reports(True)
self.assertEqual(set(apport.fileutils.get_all_system_reports()), set(tr))
self.assertEqual(set(apport.fileutils.get_new_system_reports()), set(tr))
# now mark them as seen and check again
for r in tr:
apport.fileutils.mark_report_seen(r)
self.assertEqual(set(apport.fileutils.get_all_system_reports()), set(tr))
self.assertEqual(set(apport.fileutils.get_new_system_reports()), set([]))
else:
tr = [r for r in self._create_reports(True) if "inaccessible" not in r]
> self.assertEqual(set(apport.fileutils.get_all_system_reports()), set([]))
E AssertionError: Items in the first set but not the second:
E '/tmp/tmp0l5zfk3h/rep2.crash'
E '/tmp/tmp0l5zfk3h/inaccessible.crash'
E '/tmp/tmp0l5zfk3h/rep1.crash'
tests/integration/test_fileutils.py:236: AssertionError
=============================== warnings summary ===============================
```
Skip `test_has_no_system_report` in this case, because the test would
require to call `os.chown(path, 1000, -1)` which will fail with an
permission error.
Bug: https://launchpad.net/bugs/2153134
90d7e99 to
3ba9d20
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
sbuild with the unshare backend will run as system user (but not root). This causes these two tests to fail:
Skip
test_has_no_system_reportin this case, because the test would require to callos.chown(path, 1000, -1)which will fail with an permission error.Bug: https://launchpad.net/bugs/2153134