##// END OF EJS Templates
Pytest diagnostics improvement for `IPython.testing.tools`...
Nikita Kniazev -
Show More
@@ -6,6 +6,9 b' import pytest'
6 import pathlib
6 import pathlib
7 import shutil
7 import shutil
8
8
9 # Must register before it gets imported
10 pytest.register_assert_rewrite("IPython.testing.tools")
11
9 from .testing import tools
12 from .testing import tools
10
13
11
14
@@ -181,7 +181,10 b' def ipexec(fname, options=None, commands=()):'
181 -------
181 -------
182 ``(stdout, stderr)`` of ipython subprocess.
182 ``(stdout, stderr)`` of ipython subprocess.
183 """
183 """
184 if options is None: options = []
184 __tracebackhide__ = True
185
186 if options is None:
187 options = []
185
188
186 cmdargs = default_argv() + options
189 cmdargs = default_argv() + options
187
190
@@ -239,6 +242,7 b" def ipexec_validate(fname, expected_out, expected_err='',"
239 -------
242 -------
240 None
243 None
241 """
244 """
245 __tracebackhide__ = True
242
246
243 out, err = ipexec(fname, options, commands)
247 out, err = ipexec(fname, options, commands)
244 #print 'OUT', out # dbg
248 #print 'OUT', out # dbg
@@ -247,12 +251,16 b" def ipexec_validate(fname, expected_out, expected_err='',"
247 # more informative than simply having an empty stdout.
251 # more informative than simply having an empty stdout.
248 if err:
252 if err:
249 if expected_err:
253 if expected_err:
250 assert err.strip().splitlines() == expected_err.strip().splitlines()
254 assert "\n".join(err.strip().splitlines()) == "\n".join(
255 expected_err.strip().splitlines()
256 )
251 else:
257 else:
252 raise ValueError('Running file %r produced error: %r' %
258 raise ValueError('Running file %r produced error: %r' %
253 (fname, err))
259 (fname, err))
254 # If no errors or output on stderr was expected, match stdout
260 # If no errors or output on stderr was expected, match stdout
255 assert out.strip().splitlines() == expected_out.strip().splitlines()
261 assert "\n".join(out.strip().splitlines()) == "\n".join(
262 expected_out.strip().splitlines()
263 )
256
264
257
265
258 class TempFileMixin(unittest.TestCase):
266 class TempFileMixin(unittest.TestCase):
@@ -312,6 +320,8 b' def check_pairs(func, pairs):'
312 None. Raises an AssertionError if any output does not match the expected
320 None. Raises an AssertionError if any output does not match the expected
313 value.
321 value.
314 """
322 """
323 __tracebackhide__ = True
324
315 name = getattr(func, "func_name", getattr(func, "__name__", "<unknown>"))
325 name = getattr(func, "func_name", getattr(func, "__name__", "<unknown>"))
316 for inp, expected in pairs:
326 for inp, expected in pairs:
317 out = func(inp)
327 out = func(inp)
@@ -354,6 +364,8 b' class AssertPrints(object):'
354 setattr(sys, self.channel, self.buffer if self.suppress else self.tee)
364 setattr(sys, self.channel, self.buffer if self.suppress else self.tee)
355
365
356 def __exit__(self, etype, value, traceback):
366 def __exit__(self, etype, value, traceback):
367 __tracebackhide__ = True
368
357 try:
369 try:
358 if value is not None:
370 if value is not None:
359 # If an error was raised, don't check anything else
371 # If an error was raised, don't check anything else
@@ -381,6 +393,8 b' class AssertNotPrints(AssertPrints):'
381
393
382 Counterpart of AssertPrints"""
394 Counterpart of AssertPrints"""
383 def __exit__(self, etype, value, traceback):
395 def __exit__(self, etype, value, traceback):
396 __tracebackhide__ = True
397
384 try:
398 try:
385 if value is not None:
399 if value is not None:
386 # If an error was raised, don't check anything else
400 # If an error was raised, don't check anything else
General Comments 0
You need to be logged in to leave comments. Login now