diff options
author | Jason R. Coombs <jaraco@jaraco.com> | 2019-12-31 13:29:43 -0500 |
---|---|---|
committer | Jason R. Coombs <jaraco@jaraco.com> | 2019-12-31 13:29:43 -0500 |
commit | 9c40ab8861d1bbc18d1c8032f678e2ca15ada7ff (patch) | |
tree | 06c1a5523ea060324dcb828cc8d5249796739e3d | |
parent | 47aab6525101bda3e2c7af1588b7abf5f6608b65 (diff) | |
download | external_python_setuptools-9c40ab8861d1bbc18d1c8032f678e2ca15ada7ff.tar.gz external_python_setuptools-9c40ab8861d1bbc18d1c8032f678e2ca15ada7ff.tar.bz2 external_python_setuptools-9c40ab8861d1bbc18d1c8032f678e2ca15ada7ff.zip |
Rewrite TestSdistTest setup/teardown_method as pytest fixture.
-rw-r--r-- | setuptools/tests/test_sdist.py | 35 |
1 files changed, 17 insertions, 18 deletions
diff --git a/setuptools/tests/test_sdist.py b/setuptools/tests/test_sdist.py index b27c4a83..f2e9a5ec 100644 --- a/setuptools/tests/test_sdist.py +++ b/setuptools/tests/test_sdist.py @@ -91,30 +91,29 @@ fail_on_latin1_encoded_filenames = pytest.mark.xfail( ) +def touch(path): + path.write_text('', encoding='utf-8') + + class TestSdistTest: - def setup_method(self, method): - self.temp_dir = tempfile.mkdtemp() - with open(os.path.join(self.temp_dir, 'setup.py'), 'w') as f: - f.write(SETUP_PY) + @pytest.fixture(autouse=True) + def source_dir(self, tmpdir): + self.temp_dir = str(tmpdir) + (tmpdir / 'setup.py').write_text(SETUP_PY, encoding='utf-8') # Set up the rest of the test package - test_pkg = os.path.join(self.temp_dir, 'sdist_test') - os.mkdir(test_pkg) - data_folder = os.path.join(self.temp_dir, "d") - os.mkdir(data_folder) + test_pkg = tmpdir / 'sdist_test' + test_pkg.mkdir() + data_folder = tmpdir / 'd' + data_folder.mkdir() # *.rst was not included in package_data, so c.rst should not be # automatically added to the manifest when not under version control - for fname in ['__init__.py', 'a.txt', 'b.txt', 'c.rst', - os.path.join(data_folder, "e.dat")]: - # Just touch the files; their contents are irrelevant - open(os.path.join(test_pkg, fname), 'w').close() - - self.old_cwd = os.getcwd() - os.chdir(self.temp_dir) + for fname in ['__init__.py', 'a.txt', 'b.txt', 'c.rst']: + touch(test_pkg / fname) + touch(data_folder / 'e.dat') - def teardown_method(self, method): - os.chdir(self.old_cwd) - shutil.rmtree(self.temp_dir) + with tmpdir.as_cwd(): + yield def test_package_data_in_sdist(self): """Regression test for pull request #4: ensures that files listed in |