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
1=== modified file 'debian/control'
2--- debian/control 2015-07-17 13:21:14 +0000
3+++ debian/control 2015-07-21 03:25:30 +0000
4@@ -10,6 +10,7 @@
5 pyflakes,
6 python3,
7 python3-apt,
8+ python3-fixtures,
9 python3-setuptools,
10 python3-yaml,
11 Homepage: https://launchpad.net/snapcraft
12
13=== modified file 'snapcraft/tests/__init__.py'
14--- snapcraft/tests/__init__.py 2015-07-15 08:57:44 +0000
15+++ snapcraft/tests/__init__.py 2015-07-21 03:25:30 +0000
16@@ -14,12 +14,15 @@
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19
20-import unittest
21+import fixtures
22
23 import snapcraft.dirs
24-
25-
26-class TestCase(unittest.TestCase):
27+from snapcraft.tests import fixture_setup
28+
29+
30+class TestCase(fixtures.TestWithFixtures):
31+
32 def setUp(self):
33 super().setUp()
34 snapcraft.dirs.setup_dirs()
35+ self.useFixture(fixture_setup.TempCWD())
36
37=== added file 'snapcraft/tests/fixture_setup.py'
38--- snapcraft/tests/fixture_setup.py 1970-01-01 00:00:00 +0000
39+++ snapcraft/tests/fixture_setup.py 2015-07-21 03:25:30 +0000
40@@ -0,0 +1,29 @@
41+# -*- Mode:Python; indent-tabs-mode:nil; tab-width:4 -*-
42+#
43+# Copyright (C) 2015 Canonical Ltd
44+#
45+# This program is free software: you can redistribute it and/or modify
46+# it under the terms of the GNU General Public License version 3 as
47+# published by the Free Software Foundation.
48+#
49+# This program is distributed in the hope that it will be useful,
50+# but WITHOUT ANY WARRANTY; without even the implied warranty of
51+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
52+# GNU General Public License for more details.
53+#
54+# You should have received a copy of the GNU General Public License
55+# along with this program. If not, see <http://www.gnu.org/licenses/>.
56+
57+import os
58+
59+import fixtures
60+
61+
62+class TempCWD(fixtures.TempDir):
63+
64+ def setUp(self):
65+ """Create a temporary directory an cd into it for the test duration."""
66+ super().setUp()
67+ current_dir = os.getcwd()
68+ self.addCleanup(os.chdir, current_dir)
69+ os.chdir(self.path)

Subscribers

People subscribed via source and target branches

to all changes: