Skip to content

test: fix running tests as non-root system user#626

Open
bdrung wants to merge 1 commit into
canonical:mainfrom
bdrung:fix-system-user-tests
Open

test: fix running tests as non-root system user#626
bdrung wants to merge 1 commit into
canonical:mainfrom
bdrung:fix-system-user-tests

Conversation

@bdrung

@bdrung bdrung commented May 19, 2026

Copy link
Copy Markdown
Member

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

@codecov

codecov Bot commented May 19, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 84.38%. Comparing base (07b90b3) to head (3ba9d20).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@bdrung bdrung force-pushed the fix-system-user-tests branch from 86f92cf to 90d7e99 Compare May 19, 2026 13:54
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
@bdrung bdrung force-pushed the fix-system-user-tests branch from 90d7e99 to 3ba9d20 Compare June 18, 2026 11:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant