summaryrefslogtreecommitdiff
path: root/setuptools/tests/test_bdist_egg.py
diff options
context:
space:
mode:
Diffstat (limited to 'setuptools/tests/test_bdist_egg.py')
-rw-r--r--setuptools/tests/test_bdist_egg.py62
1 files changed, 29 insertions, 33 deletions
diff --git a/setuptools/tests/test_bdist_egg.py b/setuptools/tests/test_bdist_egg.py
index 1b406f5c..d29ef441 100644
--- a/setuptools/tests/test_bdist_egg.py
+++ b/setuptools/tests/test_bdist_egg.py
@@ -2,10 +2,9 @@
"""
import os
import re
-import shutil
-import site
-import tempfile
-import unittest
+
+import pytest
+import mock
from setuptools.dist import Distribution
@@ -18,30 +17,31 @@ from setuptools import setup
setup(name='foo', py_modules=['hi'])
"""
-class TestDevelopTest(unittest.TestCase):
-
- def setUp(self):
- self.dir = tempfile.mkdtemp()
- self.old_cwd = os.getcwd()
- os.chdir(self.dir)
- with open('setup.py', 'w') as f:
- f.write(SETUP_PY)
- with open('hi.py', 'w') as f:
- f.write('1\n')
- self.old_base = site.USER_BASE
- site.USER_BASE = tempfile.mkdtemp()
- self.old_site = site.USER_SITE
- site.USER_SITE = tempfile.mkdtemp()
-
- def tearDown(self):
- os.chdir(self.old_cwd)
- shutil.rmtree(self.dir)
- shutil.rmtree(site.USER_BASE)
- shutil.rmtree(site.USER_SITE)
- site.USER_BASE = self.old_base
- site.USER_SITE = self.old_site
-
- def test_bdist_egg(self):
+@pytest.yield_fixture
+def user_override():
+ """
+ Override site.USER_BASE and site.USER_SITE with temporary directories in
+ a context.
+ """
+ with contexts.tempdir() as user_base:
+ with mock.patch('site.USER_BASE', user_base):
+ with contexts.tempdir() as user_site:
+ with mock.patch('site.USER_SITE', user_site):
+ yield
+
+
+@pytest.yield_fixture
+def setup_context(tmpdir):
+ with (tmpdir/'setup.py').open('w') as f:
+ f.write(SETUP_PY)
+ with (tmpdir/'hi.py').open('w') as f:
+ f.write('1\n')
+ with tmpdir.as_cwd():
+ yield tmpdir
+
+
+class TestDevelopTest:
+ def test_bdist_egg(self, setup_context, user_override):
dist = Distribution(dict(
script_name='setup.py',
script_args=['bdist_egg'],
@@ -55,8 +55,4 @@ class TestDevelopTest(unittest.TestCase):
# let's see if we got our egg link at the right place
[content] = os.listdir('dist')
- self.assertTrue(re.match('foo-0.0.0-py[23].\d.egg$', content))
-
-def test_suite():
- return unittest.makeSuite(TestDevelopTest)
-
+ assert re.match('foo-0.0.0-py[23].\d.egg$', content)