Unit tests should not depend on their running environment

Bug #1883224 reported by Chris MacNaughton
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
diskimage-builder
Fix Released
Undecided
Chris MacNaughton

Bug Description

When the environment exports environment variables that are mocked in unit testing (eg: already defining ARCH: https://github.com/openstack/diskimage-builder/blob/2e6a7f949c19ca81e545592462ab393ff5575245/diskimage_builder/elements/package-installs/tests/test_package_squash.py#L76), the tests fail because:

Failed to import test module: diskimage_builder.elements.package-installs.tests.test_package_squash
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/unittest2/loader.py", line 456, in _find_test_path
    module = self._get_module_from_name(name)
  File "/usr/lib/python3/dist-packages/unittest2/loader.py", line 395, in _get_module_from_name
    __import__(name)
  File "/build/python-diskimage-builder-3.0.0/diskimage_builder/elements/package-installs/tests/test_package_squash.py", line 53, in <module>
    class TestPackageInstall(base.BaseTestCase):
  File "/build/python-diskimage-builder-3.0.0/diskimage_builder/elements/package-installs/tests/test_package_squash.py", line 76, in TestPacka
geInstall
    @mock.patch.object(os, 'environ', dict(ARCH='arm64', **os.environ))
TypeError: type object got multiple values for keyword argument 'ARCH'

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to diskimage-builder (master)

Fix proposed to branch: master
Review: https://review.opendev.org/735309

Changed in diskimage-builder:
assignee: nobody → Chris MacNaughton (chris.macnaughton)
status: New → In Progress
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to diskimage-builder (master)

Reviewed: https://review.opendev.org/735309
Committed: https://git.openstack.org/cgit/openstack/diskimage-builder/commit/?id=8f57ed9b9ed3e4dcb348487b29c18d2772147e07
Submitter: Zuul
Branch: master

commit 8f57ed9b9ed3e4dcb348487b29c18d2772147e07
Author: Chris MacNaughton <email address hidden>
Date: Fri Jun 12 10:37:20 2020 +0200

    Stop bringing the test environment into the mocks

    Change-Id: I1780f186cf107242cacd6d3da7a5bc81a330b536
    Closes-Bug: #1883224

Changed in diskimage-builder:
status: In Progress → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.