MCPcopy Create free account
hub / github.com/ipython/ipython / PyTestController

Class PyTestController

IPython/testing/iptestcontroller.py:113–200  ·  view source on GitHub ↗

Run Python tests using IPython.testing.iptest

Source from the content-addressed store, hash-verified

111
112
113class PyTestController(TestController):
114 """Run Python tests using IPython.testing.iptest"""
115 #: str, Python command to execute in subprocess
116 pycmd = None
117
118 def __init__(self, section, options):
119 """Create new test runner."""
120 TestController.__init__(self)
121 self.section = section
122 # pycmd is put into cmd[2] in PyTestController.launch()
123 self.cmd = [sys.executable, '-c', None, section]
124 self.pycmd = "from IPython.testing.iptest import run_iptest; run_iptest()"
125 self.options = options
126
127 def setup(self):
128 ipydir = TemporaryDirectory()
129 self.dirs.append(ipydir)
130 self.env['IPYTHONDIR'] = ipydir.name
131 self.workingdir = workingdir = TemporaryDirectory()
132 self.dirs.append(workingdir)
133 self.env['IPTEST_WORKING_DIR'] = workingdir.name
134 # This means we won't get odd effects from our own matplotlib config
135 self.env['MPLCONFIGDIR'] = workingdir.name
136 # For security reasons (http://bugs.python.org/issue16202), use
137 # a temporary directory to which other users have no access.
138 self.env['TMPDIR'] = workingdir.name
139
140 # Add a non-accessible directory to PATH (see gh-7053)
141 noaccess = os.path.join(self.workingdir.name, "_no_access_")
142 self.noaccess = noaccess
143 os.mkdir(noaccess, 0)
144
145 PATH = os.environ.get('PATH', '')
146 if PATH:
147 PATH = noaccess + os.pathsep + PATH
148 else:
149 PATH = noaccess
150 self.env['PATH'] = PATH
151
152 # From options:
153 if self.options.xunit:
154 self.add_xunit()
155 if self.options.coverage:
156 self.add_coverage()
157 self.env['IPTEST_SUBPROC_STREAMS'] = self.options.subproc_streams
158 self.cmd.extend(self.options.extra_args)
159
160 def cleanup(self):
161 """
162 Make the non-accessible directory created in setup() accessible
163 again, otherwise deleting the workingdir will fail.
164 """
165 os.chmod(self.noaccess, stat.S_IRWXU)
166 TestController.cleanup(self)
167
168 @property
169 def will_run(self):
170 try:

Callers 1

prepare_controllersFunction · 0.85

Calls

no outgoing calls

Tested by 1

prepare_controllersFunction · 0.68