Skip to content

Commit

Permalink
Move setup/teardown from BuildExtTestCase into a fixture.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaraco committed Aug 2, 2022
1 parent c899a99 commit cb50452
Showing 1 changed file with 18 additions and 24 deletions.
42 changes: 18 additions & 24 deletions distutils/tests/test_build_ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os
from io import StringIO
import textwrap
import site

from distutils.core import Distribution
from distutils.command.build_ext import build_ext
Expand Down Expand Up @@ -32,35 +33,28 @@
ALREADY_TESTED = False


class BuildExtTestCase(TempdirManager, LoggingSilencer, unittest.TestCase):
def setUp(self):
# Create a simple test environment
super().setUp()
self.tmp_dir = self.mkdtemp()
import site

self.old_user_base = site.USER_BASE
site.USER_BASE = self.mkdtemp()
from distutils.command import build_ext
@pytest.fixture(autouse=True)
def user_site_dir(request):
self = request.instance
self.tmp_dir = self.mkdtemp()
from distutils.command import build_ext

build_ext.USER_BASE = site.USER_BASE
orig_user_base = site.USER_BASE

# bpo-30132: On Windows, a .pdb file may be created in the current
# working directory. Create a temporary working directory to cleanup
# everything at the end of the test.
change_cwd = os_helper.change_cwd(self.tmp_dir)
change_cwd.__enter__()
self.addCleanup(change_cwd.__exit__, None, None, None)
site.USER_BASE = self.mkdtemp()
build_ext.USER_BASE = site.USER_BASE

def tearDown(self):
import site
# bpo-30132: On Windows, a .pdb file may be created in the current
# working directory. Create a temporary working directory to cleanup
# everything at the end of the test.
with os_helper.change_cwd(self.tmp_dir):
yield

site.USER_BASE = self.old_user_base
from distutils.command import build_ext
site.USER_BASE = orig_user_base
build_ext.USER_BASE = orig_user_base

build_ext.USER_BASE = self.old_user_base
super().tearDown()

class TestBuildExt(TempdirManager, LoggingSilencer):
def build_ext(self, *args, **kwargs):
return build_ext(*args, **kwargs)

Expand Down Expand Up @@ -557,7 +551,7 @@ def _try_compile_deployment_target(self, operator, target):
self.fail("Wrong deployment target during compilation")


class ParallelBuildExtTestCase(BuildExtTestCase):
class TestParallelBuildExt(TestBuildExt):
def build_ext(self, *args, **kwargs):
build_ext = super().build_ext(*args, **kwargs)
build_ext.parallel = True
Expand Down

0 comments on commit cb50452

Please sign in to comment.