/
cli_unittest.py
779 lines (718 loc) · 28 KB
/
cli_unittest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import os
import os.path
import pty
import re
import subprocess
import sys
import threading
import unittest
import testslide
class TestCliBase(unittest.TestCase):
SAMPLE_TESTS_PATH = os.path.dirname(__file__) + "/sample_tests.py"
def setUp(self):
self.argv = [self.SAMPLE_TESTS_PATH]
self.env = {
"COVERAGE_PROCESS_START": ".coveragerc",
}
super(TestCliBase, self).setUp()
def run_testslide(
self,
tty_stdout=False,
expected_return_code=0,
expected_stdout=None,
expected_stdout_startswith=None,
expected_in_stdout=None,
expected_not_in_stdout=None,
expected_regex_in_stdout=None,
show_testslide_stack_trace=True,
):
args = [
sys.executable,
"-m",
"testslide.executor.cli",
]
if show_testslide_stack_trace:
args.append("--show-testslide-stack-trace")
args.extend(self.argv)
env = dict(os.environ)
env.update(self.env)
if tty_stdout:
stdout_master_fd, stdout_slave_fd = pty.openpty()
encoding = sys.getdefaultencoding()
with subprocess.Popen(
args,
bufsize=1,
stdin=subprocess.DEVNULL,
stdout=stdout_slave_fd if tty_stdout else subprocess.PIPE,
stderr=subprocess.PIPE,
encoding=encoding,
env=env,
universal_newlines=True,
) as popen:
stdout_chunks = []
stderr_chunks = []
def _process_output(fd, callback):
while True:
try:
chunk = os.read(fd, 8192)
except OSError:
break
if len(chunk):
callback(chunk)
else:
break
if tty_stdout:
stdout_fileno = stdout_master_fd
else:
stdout_fileno = popen.stdout.fileno()
process_stdout_thread = threading.Thread(
target=_process_output,
name="process_stdout",
args=(stdout_fileno, lambda line: stdout_chunks.append(line)),
)
process_stdout_thread.start()
process_stderr_thread = threading.Thread(
target=_process_output,
name="process_stderr",
args=(popen.stderr.fileno(), lambda line: stderr_chunks.append(line)),
)
process_stderr_thread.start()
return_code = popen.wait()
if tty_stdout:
os.close(stdout_slave_fd)
process_stdout_thread.join()
process_stderr_thread.join()
stdout_output = "".join(chunk.decode(encoding) for chunk in stdout_chunks)
stderr_output = "".join(chunk.decode(encoding) for chunk in stderr_chunks)
output = ""
if stdout_output:
output += f"STDOUT:\n{stdout_output}\n"
if stderr_output:
output += f"STDERR:\n{stderr_output}\n"
self.assertEqual(
return_code,
expected_return_code,
f"Command {args} returned {return_code}, "
f"expected {expected_return_code}.\n{output}",
)
if expected_stdout:
self.assertEqual(
stdout_output,
expected_stdout,
f"Command {args} expected to have have this stdout:\n\n"
f"{expected_stdout}\n\n"
f"But output was different:\n"
f"{stdout_output}",
)
if expected_stdout_startswith:
self.assertTrue(
stdout_output.startswith(expected_stdout_startswith),
f"Command {args} expected to have have its stdout starting with:\n\n"
f"{expected_stdout_startswith}\n\n"
f"But output was different:\n"
f"{stdout_output}",
)
if expected_in_stdout:
self.assertTrue(
expected_in_stdout in stdout_output,
f"Command {args} expected to have have in its stdout:\n\n"
f"{expected_in_stdout}\n\n"
f"But output was different:\n"
f"{stdout_output}",
)
if expected_not_in_stdout:
self.assertTrue(
expected_not_in_stdout not in stdout_output,
f"Command {args} expected to not have have in its stdout:\n\n"
f"{expected_not_in_stdout}\n\n"
f"But output was different:\n"
f"{stdout_output}",
)
if expected_regex_in_stdout:
self.assertTrue(
re.fullmatch(expected_regex_in_stdout, stdout_output, flags=re.DOTALL),
f"Command {args} expected to have have its stdout matching the regexp:\n\n"
f"{expected_regex_in_stdout}\n\n"
f"But output was different:\n"
f"{stdout_output}",
)
@staticmethod
def bright(text):
return "\x1b[0m\x1b[1m{}\x1b[0m".format(text)
@staticmethod
def green(text):
return "\x1b[0m\x1b[32m{}\x1b[0m".format(text)
@staticmethod
def red(text):
return "\x1b[0m\x1b[31m{}\x1b[0m".format(text)
@staticmethod
def yellow(text):
return "\x1b[0m\x1b[33m{}\x1b[0m".format(text)
@staticmethod
def cyan(text):
return "\x1b[0m\x1b[36m{}\x1b[0m".format(text)
class TestCliList(TestCliBase):
def setUp(self):
super().setUp()
self.argv.insert(0, "--list")
def test_list(self):
"""
With --list, print test names one per line.
"""
self.run_testslide(
expected_stdout=(
"top context: passing example\n"
"top context: failing example\n"
"top context: focused example\n"
"top context: skipped example\n"
"top context: unittest SkipTest\n"
"top context, nested context: passing nested example\n"
"tests.sample_tests.SampleTestCase: test_failing\n"
"tests.sample_tests.SampleTestCase: test_passing\n"
"tests.sample_tests.SampleTestCase: test_skipped\n"
)
)
class TestCliQuiet(TestCliBase):
def setUp(self):
super().setUp()
self.env = {"PRINT": "True"}
def test_with_quiet(self):
"""
With --quiet, swallow both stderr and stdout unless the test fails.
"""
self.argv.insert(0, "--quiet")
self.run_testslide(
expected_return_code=1,
expected_stdout_startswith=(
"top context\n"
" passing example: PASS\n"
"stdout:\n"
"failing_example stdout\n"
"\n"
"stderr:\n"
"failing_example stderr\n"
"\n"
" failing example: SimulatedFailure: test failure (extra)\n"
" *focused example: PASS\n"
" skipped example: SKIP\n"
" unittest SkipTest: SKIP\n"
" nested context\n"
" passing nested example: PASS\n"
"tests.sample_tests.SampleTestCase\n"
"stdout:\n"
"test_fail stdout\n"
"\n"
"stderr:\n"
"test_fail stderr\n"
"\n"
" test_failing: AssertionError: Third\n"
" test_passing: PASS\n"
" test_skipped: SKIP\n"
"\n"
"Failures:\n"
# TODO Rest of the output
),
)
def test_without_quiet(self):
"""
Without --quiet, allow test stdout and stderr to go on.
"""
self.run_testslide(
expected_return_code=1,
expected_stdout_startswith=(
"top context\n"
"passing_example stdout\n"
" passing example: PASS\n"
"failing_example stdout\n"
" failing example: SimulatedFailure: test failure (extra)\n"
"focused_example stdout\n"
" *focused example: PASS\n"
" skipped example: SKIP\n"
"unittest_SkipTest stdout\n"
" unittest SkipTest: SKIP\n"
" nested context\n"
"passing_nested_example stdout\n"
" passing nested example: PASS\n"
"tests.sample_tests.SampleTestCase\n"
"test_fail stdout\n"
" test_failing: AssertionError: Third\n"
"test_pass stdout\n"
" test_passing: PASS\n"
" test_skipped: SKIP\n"
"\n"
"Failures:\n"
# TODO Rest of the output
),
)
class FormatterMixin:
def test_prints_exceptions_with_cause(self):
self.run_testslide(
tty_stdout=True,
expected_return_code=1,
expected_in_stdout=(
' File \x1b[36m"tests/sample_tests.py"\x1b[39;49;00m, line \x1b[94m76\x1b[39;49;00m, in test_failing\x1b[37m\x1b[39;49;00m\r\n'
' \x1b[37m \x1b[39;49;00m\x1b[94mraise\x1b[39;49;00m \x1b[36mAssertionError\x1b[39;49;00m(\x1b[33m"\x1b[39;49;00m\x1b[33mThird\x1b[39;49;00m\x1b[33m"\x1b[39;49;00m) \x1b[94mfrom\x1b[39;49;00m \x1b[04m\x1b[36mcause\x1b[39;49;00m\x1b[37m\x1b[39;49;00m\r\n'
"\x1b[0m\x1b[31m Caused by \x1b[0m\x1b[0m\x1b[31mAssertionError: Second\x1b[0m\r\n"
' File \x1b[36m"tests/sample_tests.py"\x1b[39;49;00m, line \x1b[94m74\x1b[39;49;00m, in test_failing\x1b[37m\x1b[39;49;00m\r\n'
' \x1b[37m \x1b[39;49;00m\x1b[94mraise\x1b[39;49;00m \x1b[36mAssertionError\x1b[39;49;00m(\x1b[33m"\x1b[39;49;00m\x1b[33mSecond\x1b[39;49;00m\x1b[33m"\x1b[39;49;00m) \x1b[94mfrom\x1b[39;49;00m \x1b[04m\x1b[36mcause\x1b[39;49;00m\x1b[37m\x1b[39;49;00m\r\n'
"\x1b[0m\x1b[31m Caused by \x1b[0m\x1b[0m\x1b[31mAssertionError: First\x1b[0m\r\n"
' File \x1b[36m"tests/sample_tests.py"\x1b[39;49;00m, line \x1b[94m72\x1b[39;49;00m, in test_failing\x1b[37m\x1b[39;49;00m\r\n'
' \x1b[37m \x1b[39;49;00m\x1b[94mraise\x1b[39;49;00m \x1b[36mAssertionError\x1b[39;49;00m(\x1b[33m"\x1b[39;49;00m\x1b[33mFirst\x1b[39;49;00m\x1b[33m"\x1b[39;49;00m)\x1b[37m\x1b[39;49;00m\r\n'
),
)
def test_default_trim_path_prefix(self):
"""
Default value for --trim-path-prefix trims path shared with
testslide itself.
"""
self.run_testslide(
expected_return_code=1,
expected_in_stdout=('File "tests/sample_tests.py", line'),
)
def test_nonempty_trim_path_prefix(self):
"""
Trims prefix passed to --trim-path-prefix.
"""
self.argv.append("--trim-path-prefix")
self.argv.append(os.path.dirname(self.SAMPLE_TESTS_PATH) + "/")
self.run_testslide(
expected_return_code=1,
expected_in_stdout=(
'File "' + os.path.basename(self.SAMPLE_TESTS_PATH) + '", line'
),
)
def test_empty_trim_path_prefix(self):
"""
Trims nothing if '' passed to --trim-path-prefix.
"""
self.argv.append("--trim-path-prefix")
self.argv.append("")
self.run_testslide(
expected_return_code=1,
expected_in_stdout=('File "' + self.SAMPLE_TESTS_PATH + '", line'),
)
def test_not_show_testslide_stack_trace(self):
self.run_testslide(
expected_return_code=1,
show_testslide_stack_trace=False,
expected_not_in_stdout=os.path.abspath(os.path.dirname(testslide.__file__)),
)
class TestCliDocumentFormatter(FormatterMixin, TestCliBase):
def setUp(self):
super().setUp()
self.argv = ["--format", "documentation"] + self.argv
def test_colored_output_to_terminal(self):
"""
Execute all examples in the order defined with colored output.
"""
self.run_testslide(
tty_stdout=True,
expected_return_code=1,
expected_stdout_startswith=(
self.bright("top context")
+ "\r\n"
+ self.green(" passing example")
+ "\r\n"
+ self.red(" failing example: SimulatedFailure: test failure (extra)")
+ "\r\n"
+ self.green(" *focused example")
+ "\r\n"
+ self.yellow(" skipped example")
+ "\r\n"
+ self.yellow(" unittest SkipTest")
+ "\r\n"
+ self.bright(" nested context")
+ "\r\n"
+ self.green(" passing nested example")
+ "\r\n"
# TODO Rest of the output
),
)
def test_colored_output_with_force_color(self):
"""
Execute all examples in the order defined with colored output.
"""
self.argv.append("--force-color")
self.run_testslide(
expected_return_code=1,
expected_stdout_startswith=(
self.bright("top context")
+ "\n"
+ self.green(" passing example")
+ "\n"
+ self.red(" failing example: SimulatedFailure: test failure (extra)")
+ "\n"
+ self.green(" *focused example")
+ "\n"
+ self.yellow(" skipped example")
+ "\n"
+ self.yellow(" unittest SkipTest")
+ "\n"
+ self.bright(" nested context")
+ "\n"
+ self.green(" passing nested example")
+ "\n"
# TODO add remaining bits of the output (using regexes)
),
)
def test_plain_output_without_terminal(self):
"""
Execute all examples in the order defined without color.
"""
self.run_testslide(
expected_return_code=1,
expected_stdout_startswith=(
"top context\n"
" passing example: PASS\n"
" failing example: SimulatedFailure: test failure (extra)\n"
" *focused example: PASS\n"
" skipped example: SKIP\n"
" unittest SkipTest: SKIP\n"
" nested context\n"
" passing nested example: PASS\n"
"tests.sample_tests.SampleTestCase\n"
" test_failing: AssertionError: Third\n"
" test_passing: PASS\n"
" test_skipped: SKIP\n"
"\n"
"Failures:\n"
# TODO add remaining bits of the output (using regexes)
),
)
def test_shuffle(self):
"""
Shuffle execution order.
"""
self.argv.append("--shuffle")
self.argv.append("--seed")
self.argv.append("33")
self.run_testslide(
expected_return_code=1,
expected_stdout_startswith=(
"top context\n"
" passing example: PASS\n"
" unittest SkipTest: SKIP\n"
" nested context\n"
" passing nested example: PASS\n"
" failing example: SimulatedFailure: test failure (extra)\n"
"tests.sample_tests.SampleTestCase\n"
" test_passing: PASS\n"
" test_skipped: SKIP\n"
" test_failing: AssertionError: Third\n"
"top context\n"
" skipped example: SKIP\n"
" *focused example: PASS\n"
"\n"
"Failures:\n"
# TODO add remaining bits of the output (using regexes)
),
)
def test_focus(self):
"""
Execute only focused examples.
"""
self.argv.append("--focus")
self.run_testslide(
expected_stdout_startswith=(
"top context\n"
" *focused example: PASS\n"
# TODO add remaining bits of the output (using regexes)
)
)
def test_fail_if_focus(self):
"""
Fail because there are focused tests and --fail-if-focused
"""
self.argv.append("--fail-if-focused")
self.run_testslide(
expected_return_code=1,
expected_stdout_startswith=(
"top context\n"
" passing example: PASS\n"
" failing example: SimulatedFailure: test failure (extra)\n"
" *focused example: AssertionError: Focused example not allowed with --fail-if-focused. Please remove the focus to allow the test to run.\n"
" skipped example: SKIP\n"
" unittest SkipTest: SKIP\n"
" nested context\n"
" passing nested example: PASS\n"
"tests.sample_tests.SampleTestCase\n"
" test_failing: AssertionError: Third\n"
" test_passing: PASS\n"
" test_skipped: SKIP\n"
"\n"
"Failures:\n"
),
)
def test_fail_fast(self):
"""
Stop execution when first example fails.
"""
self.argv.append("--fail-fast")
self.run_testslide(
expected_return_code=1,
expected_stdout_startswith=(
"top context\n"
" passing example: PASS\n"
" failing example: SimulatedFailure: test failure (extra)\n"
"\n"
"Failures:\n"
),
)
def test_text_filter(self):
"""
Execute only examples matching partial text filter.
"""
self.argv.append("--filter-text")
self.argv.append("nested context: passing nested ex")
self.run_testslide(
expected_return_code=0,
expected_stdout_startswith=(
"top context\n"
" nested context\n"
" passing nested example: PASS\n"
),
)
def test_regexp_filter(self):
"""
Execute only examples matching regex filter.
"""
self.argv.append("--filter-regex")
self.argv.append(".*passing nested.*")
self.run_testslide(
expected_return_code=0,
expected_stdout_startswith=(
"top context\n"
" nested context\n"
" passing nested example: PASS\n"
),
)
def test_exclude_regexp(self):
"""
Skip examples matching regex filter.
"""
self.argv.append("--exclude-regex")
self.argv.append(".*failing.*")
self.run_testslide(
expected_return_code=0,
expected_stdout_startswith=(
"top context\n"
" passing example: PASS\n"
" *focused example: PASS\n"
" skipped example: SKIP\n"
" unittest SkipTest: SKIP\n"
" nested context\n"
" passing nested example: PASS\n"
"tests.sample_tests.SampleTestCase\n"
" test_passing: PASS\n"
" test_skipped: SKIP\n"
),
)
def test_dsl_debug(self):
self.argv.append("--dsl-debug")
self.run_testslide(
expected_return_code=1,
expected_regex_in_stdout=(
"top context\n"
r" example: passing_example @ tests/sample_tests.py:\d+\n"
" passing example: PASS\n"
r" example: failing_example @ tests/sample_tests.py:\d+\n"
r" failing example: SimulatedFailure: test failure \(extra\)\n"
r" example: focused_example @ tests/sample_tests.py:\d+\n"
r" \*focused example: PASS\n"
" skipped example: SKIP\n"
r" example: unittest_SkipTest @ tests/sample_tests.py:\d+\n"
" unittest SkipTest: SKIP\n"
" nested context\n"
r" example: passing_nested_example @ tests/sample_tests.py:\d+\n"
" passing nested example: PASS\n"
"tests.sample_tests.SampleTestCase\n"
" test_failing: AssertionError: Third\n"
" test_passing: PASS\n"
" test_skipped: SKIP\n"
".*"
),
)
class TestCliProgressFormatter(FormatterMixin, TestCliBase):
def setUp(self):
super().setUp()
self.argv.append("--format")
self.argv.append("progress")
def test_ouputs_dots(self):
self.run_testslide(
expected_return_code=1,
expected_stdout_startswith=(".F.SS.F.S" + "\nFailures:"),
)
def test_ouputs_colored_dots_with_terminal(self):
self.maxDiff = None
self.run_testslide(
tty_stdout=True,
expected_return_code=1,
expected_stdout_startswith=(
self.green(".")
+ self.red("F")
+ self.green(".")
+ self.yellow("S")
+ self.yellow("S")
+ self.green(".")
+ self.red("F")
+ self.green(".")
+ self.yellow("S")
+ self.red("\r\nFailures:")
),
)
def test_dsl_debug(self):
self.argv.append("--dsl-debug")
self.run_testslide(
expected_return_code=1,
expected_regex_in_stdout=(
"\n"
r"example: passing_example @ tests/sample_tests.py:\d+\n"
".\n"
r"example: failing_example @ tests/sample_tests.py:\d+\n"
"F\n"
r"example: focused_example @ tests/sample_tests.py:\d+\n"
".\n"
"S\n"
r"example: unittest_SkipTest @ tests/sample_tests.py:\d+\n"
"S\n"
r"example: passing_nested_example @ tests/sample_tests.py:\d+\n"
".\n"
"F\n"
".\n"
"S\n"
),
)
class TestCliLongFormatter(FormatterMixin, TestCliBase):
def setUp(self):
super().setUp()
self.argv = ["--format", "long"] + self.argv
def test_colored_output_to_terminal(self):
"""
Execute all examples in the order defined with colored output.
"""
self.run_testslide(
tty_stdout=True,
expected_return_code=1,
expected_stdout_startswith=(
self.bright("top context: ")
+ self.green("passing example")
+ "\r\n"
+ self.bright("top context: ")
+ self.red("failing example: SimulatedFailure: test failure (extra)")
+ "\r\n"
+ self.bright("top context: ")
+ self.green("*focused example")
+ "\r\n"
+ self.bright("top context: ")
+ self.yellow("skipped example")
+ "\r\n"
+ self.bright("top context: ")
+ self.yellow("unittest SkipTest")
+ "\r\n"
+ self.bright("top context, nested context: ")
+ self.green("passing nested example")
+ "\r\n"
+ self.bright("tests.sample_tests.SampleTestCase: ")
+ self.red("test_failing: AssertionError: Third")
+ "\r\n"
+ self.bright("tests.sample_tests.SampleTestCase: ")
+ self.green("test_passing")
+ "\r\n"
+ self.bright("tests.sample_tests.SampleTestCase: ")
+ self.yellow("test_skipped")
+ "\r\n"
# TODO Rest of the output
),
)
def test_colored_output_with_force_color(self):
"""
Execute all examples in the order defined with colored output.
"""
self.argv.append("--force-color")
self.run_testslide(
expected_return_code=1,
expected_stdout_startswith=(
self.bright("top context: ")
+ self.green("passing example")
+ "\n"
+ self.bright("top context: ")
+ self.red("failing example: SimulatedFailure: test failure (extra)")
+ "\n"
+ self.bright("top context: ")
+ self.green("*focused example")
+ "\n"
+ self.bright("top context: ")
+ self.yellow("skipped example")
+ "\n"
+ self.bright("top context: ")
+ self.yellow("unittest SkipTest")
+ "\n"
+ self.bright("top context, nested context: ")
+ self.green("passing nested example")
+ "\n"
+ self.bright("tests.sample_tests.SampleTestCase: ")
+ self.red("test_failing: AssertionError: Third")
+ "\n"
+ self.bright("tests.sample_tests.SampleTestCase: ")
+ self.green("test_passing")
+ "\n"
+ self.bright("tests.sample_tests.SampleTestCase: ")
+ self.yellow("test_skipped")
+ "\n"
# TODO Rest of the output
),
)
def test_plain_output_without_terminal(self):
"""
Execute all examples in the order defined without color.
"""
self.run_testslide(
expected_return_code=1,
expected_stdout_startswith=(
"top context: passing example: PASS\n"
"top context: failing example: SimulatedFailure: test failure (extra)\n"
"top context: *focused example: PASS\n"
"top context: skipped example: SKIP\n"
"top context: unittest SkipTest: SKIP\n"
"top context, nested context: passing nested example: PASS\n"
"tests.sample_tests.SampleTestCase: test_failing: AssertionError: Third\n"
"tests.sample_tests.SampleTestCase: test_passing: PASS\n"
"tests.sample_tests.SampleTestCase: test_skipped: SKIP\n"
# TODO add remaining bits of the output (using regexes)
),
)
def test_dsl_debug(self):
self.argv.append("--dsl-debug")
self.run_testslide(
expected_return_code=1,
expected_regex_in_stdout=(
"top context: \n"
r" example: passing_example @ tests/sample_tests.py:\d+\n"
" passing example: PASS\n"
"top context: \n"
r" example: failing_example @ tests/sample_tests.py:\d+\n"
r" failing example: SimulatedFailure: test failure \(extra\)\n"
"top context: \n"
r" example: focused_example @ tests/sample_tests.py:\d+\n"
r" \*focused example: PASS\n"
"top context: \n"
" skipped example: SKIP\n"
"top context: \n"
r" example: unittest_SkipTest @ tests/sample_tests.py:\d+\n"
" unittest SkipTest: SKIP\n"
"top context, nested context: \n"
r" example: passing_nested_example @ tests/sample_tests.py:\d+\n"
" passing nested example: PASS\n"
"tests.sample_tests.SampleTestCase: \n"
" test_failing: AssertionError: Third\n"
"tests.sample_tests.SampleTestCase: \n"
" test_passing: PASS\n"
"tests.sample_tests.SampleTestCase: \n"
" test_skipped: SKIP\n"
".*"
),
)