Merge lp:~elopio/snapcraft/test_tmp_cwd into lp:~snappy-dev/snapcraft/core

Proposed by Leo Arias
Status: Merged
Merged at revision: 100
Proposed branch: lp:~elopio/snapcraft/test_tmp_cwd
Merge into: lp:~snappy-dev/snapcraft/core
Diff against target: 69 lines (+37/-4)
3 files modified
debian/control (+1/-0)
snapcraft/tests/__init__.py (+7/-4)
snapcraft/tests/fixture_setup.py (+29/-0)
To merge this branch: bzr merge lp:~elopio/snapcraft/test_tmp_cwd
Reviewer Review Type Date Requested Status
Michael Terry (community) Approve
Review via email: mp+265352@code.launchpad.net

Commit message

Use a temporary cwd during the tests.
Added python3-fixtures as a build dependency.

Description of the change

There are some tests that generate directories.
If they are run in the branch directory, then it will be polluted.
By changing to a tmp dir, every test can generate whatever it wants and then it will be cleaned up.

To post a comment you must log in.
Revision history for this message
Michael Terry (mterry) wrote :

Sure, looks good. mvo's copy-plugin branch [1] did something similar, but it was opt-in instead of automatic. This is more fool-proof.

[1] https://code.launchpad.net/~mvo/snapcraft/copy-plugin/+merge/264706

review: Approve
Revision history for this message
Snappy Tarmac (snappydevtarmac) wrote :

The attempt to merge lp:~elopio/snapcraft/test_tmp_cwd into lp:snapcraft failed. Below is the output from the failed tests.

EEE
======================================================================
ERROR: snapcraft.tests.test_cmds (unittest.loader.ModuleImportFailure)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python3.4/unittest/case.py", line 57, in testPartExecutor
    yield
  File "/usr/lib/python3.4/unittest/case.py", line 574, in run
    testMethod()
  File "/usr/lib/python3.4/unittest/loader.py", line 32, in testFailure
    raise exception
ImportError: Failed to import test module: snapcraft.tests.test_cmds
Traceback (most recent call last):
  File "/usr/lib/python3.4/unittest/loader.py", line 312, in _find_tests
    module = self._get_module_from_name(name)
  File "/usr/lib/python3.4/unittest/loader.py", line 290, in _get_module_from_name
    __import__(name)
  File "/tmp/tarmac/branch.JBZ6bx/snapcraft/tests/__init__.py", line 17, in <module>
    import fixtures
ImportError: No module named 'fixtures'

======================================================================
ERROR: snapcraft.tests.test_plugin (unittest.loader.ModuleImportFailure)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python3.4/unittest/case.py", line 57, in testPartExecutor
    yield
  File "/usr/lib/python3.4/unittest/case.py", line 574, in run
    testMethod()
  File "/usr/lib/python3.4/unittest/loader.py", line 32, in testFailure
    raise exception
ImportError: Failed to import test module: snapcraft.tests.test_plugin
Traceback (most recent call last):
  File "/usr/lib/python3.4/unittest/loader.py", line 312, in _find_tests
    module = self._get_module_from_name(name)
  File "/usr/lib/python3.4/unittest/loader.py", line 290, in _get_module_from_name
    __import__(name)
  File "/tmp/tarmac/branch.JBZ6bx/snapcraft/tests/__init__.py", line 17, in <module>
    import fixtures
ImportError: No module named 'fixtures'

======================================================================
ERROR: snapcraft.tests.test_yaml (unittest.loader.ModuleImportFailure)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python3.4/unittest/case.py", line 57, in testPartExecutor
    yield
  File "/usr/lib/python3.4/unittest/case.py", line 574, in run
    testMethod()
  File "/usr/lib/python3.4/unittest/loader.py", line 32, in testFailure
    raise exception
ImportError: Failed to import test module: snapcraft.tests.test_yaml
Traceback (most recent call last):
  File "/usr/lib/python3.4/unittest/loader.py", line 312, in _find_tests
    module = self._get_module_from_name(name)
  File "/usr/lib/python3.4/unittest/loader.py", line 290, in _get_module_from_name
    __import__(name)
  File "/tmp/tarmac/branch.JBZ6bx/snapcraft/tests/__init__.py", line 17, in <module>
    import fixtures
ImportError: No module named 'fixtures'

----------------------------------------------------------------------
Ran 3 tests in 0.002s

FAILED (errors=3)

Revision history for this message
Michael Terry (mterry) wrote :

Tarmac instance doesn't have python3-fixtures installed... let me see.

Revision history for this message
Michael Terry (mterry) wrote :

Manually merged.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'debian/control'
--- debian/control 2015-07-17 13:21:14 +0000
+++ debian/control 2015-07-21 03:25:30 +0000
@@ -10,6 +10,7 @@
10 pyflakes,10 pyflakes,
11 python3,11 python3,
12 python3-apt,12 python3-apt,
13 python3-fixtures,
13 python3-setuptools,14 python3-setuptools,
14 python3-yaml,15 python3-yaml,
15Homepage: https://launchpad.net/snapcraft16Homepage: https://launchpad.net/snapcraft
1617
=== modified file 'snapcraft/tests/__init__.py'
--- snapcraft/tests/__init__.py 2015-07-15 08:57:44 +0000
+++ snapcraft/tests/__init__.py 2015-07-21 03:25:30 +0000
@@ -14,12 +14,15 @@
14# You should have received a copy of the GNU General Public License14# You should have received a copy of the GNU General Public License
15# along with this program. If not, see <http://www.gnu.org/licenses/>.15# along with this program. If not, see <http://www.gnu.org/licenses/>.
1616
17import unittest17import fixtures
1818
19import snapcraft.dirs19import snapcraft.dirs
2020from snapcraft.tests import fixture_setup
2121
22class TestCase(unittest.TestCase):22
23class TestCase(fixtures.TestWithFixtures):
24
23 def setUp(self):25 def setUp(self):
24 super().setUp()26 super().setUp()
25 snapcraft.dirs.setup_dirs()27 snapcraft.dirs.setup_dirs()
28 self.useFixture(fixture_setup.TempCWD())
2629
=== added file 'snapcraft/tests/fixture_setup.py'
--- snapcraft/tests/fixture_setup.py 1970-01-01 00:00:00 +0000
+++ snapcraft/tests/fixture_setup.py 2015-07-21 03:25:30 +0000
@@ -0,0 +1,29 @@
1# -*- Mode:Python; indent-tabs-mode:nil; tab-width:4 -*-
2#
3# Copyright (C) 2015 Canonical Ltd
4#
5# This program is free software: you can redistribute it and/or modify
6# it under the terms of the GNU General Public License version 3 as
7# published by the Free Software Foundation.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with this program. If not, see <http://www.gnu.org/licenses/>.
16
17import os
18
19import fixtures
20
21
22class TempCWD(fixtures.TempDir):
23
24 def setUp(self):
25 """Create a temporary directory an cd into it for the test duration."""
26 super().setUp()
27 current_dir = os.getcwd()
28 self.addCleanup(os.chdir, current_dir)
29 os.chdir(self.path)

Subscribers

People subscribed via source and target branches

to all changes: