diff options
| author | Jason R. Coombs <jaraco@jaraco.com> | 2015-01-01 17:31:37 -0500 |
|---|---|---|
| committer | Jason R. Coombs <jaraco@jaraco.com> | 2015-01-01 17:31:37 -0500 |
| commit | 1cbdf581186e1f34f1e48673f5faf60922e66799 (patch) | |
| tree | 48302360cb4d5c116c268d5eb53304cefa8f1a54 /setuptools/tests/test_bdist_egg.py | |
| parent | ae7007467caf6d29936c0e7ff9f9d92f610aeb98 (diff) | |
| download | python-setuptools-git-1cbdf581186e1f34f1e48673f5faf60922e66799.tar.gz | |
Replace setup and teardown with pytest fixtures.
Diffstat (limited to 'setuptools/tests/test_bdist_egg.py')
| -rw-r--r-- | setuptools/tests/test_bdist_egg.py | 62 |
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) |
