Repository navigation
Expand file tree
/
Copy pathplugin_test.py
More file actions
1232 lines (1058 loc) · 27.8 KB
/
Copy pathplugin_test.py
File metadata and controls
1232 lines (1058 loc) · 27.8 KB
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
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import re
from _pytest.pytester import LineMatcher
import pytest_markdown_docs # hack: used for storing a side effect in one of the tests
def test_docstring_markdown(testdir):
testdir.makeconftest(
"""
def pytest_markdown_docs_globals():
return {"a": "hello"}
"""
)
testdir.makepyfile(
"""
def simple():
\"\"\"
```python
import pytest_markdown_docs
pytest_markdown_docs.side_effect = "hello"
```
```
not a python block
```
\"\"\"
class Parent:
def using_global(self):
\"\"\"
```python
assert a + " world" == "hello world"
```
\"\"\"
def failing():
\"\"\"
```python
assert False
```
\"\"\"
def error():
\"\"\"
```python
raise Exception("oops")
```
\"\"\"
"""
)
result = testdir.runpytest("--markdown-docs")
result.assert_outcomes(passed=2, failed=2)
assert (
getattr(pytest_markdown_docs, "side_effect", None) == "hello"
) # hack to make sure the test actually does something
def test_markdown_text_file(testdir):
testdir.makeconftest(
"""
def pytest_markdown_docs_globals():
return {"a": "hello"}
"""
)
testdir.makefile(
".md",
"""
```python
assert a + " world" == "hello world"
```
```python
assert False
```
```python
**@ # this is a syntax error
```
""",
)
result = testdir.runpytest("--markdown-docs")
result.assert_outcomes(passed=1, failed=2)
def test_only_text_collection(testdir):
testdir.makepyfile(
"""
def docstring_test():
\"\"\"
```python
assert False
```
\"\"\"
"""
)
testdir.makefile(
".md",
"""
```python
assert True
```
""",
)
result = testdir.runpytest("--markdown-docs", "--markdown-docs-only-text")
result.assert_outcomes(passed=1)
def test_only_docstring_collection(testdir):
testdir.makepyfile(
"""
def docstring_test():
\"\"\"
```python
assert True
```
\"\"\"
"""
)
testdir.makefile(
".md",
"""
```python
assert False
```
""",
)
result = testdir.runpytest("--markdown-docs", "--markdown-docs-only-docstrings")
result.assert_outcomes(passed=1)
def test_collection_scope_options_are_mutually_exclusive(testdir):
result = testdir.runpytest(
"--markdown-docs",
"--markdown-docs-only-docstrings",
"--markdown-docs-only-text",
)
assert result.ret != 0
result.stderr.fnmatch_lines(["*mutually exclusive*"])
def test_continuation(testdir):
testdir.makefile(
".md",
"""
```python
b = "hello"
```
```python continuation
assert b + " world" == "hello world"
```
""",
)
result = testdir.runpytest("--markdown-docs")
result.assert_outcomes(passed=2)
def test_traceback(testdir):
testdir.makefile(
".md",
"""
yada yada yada
```python
def foo():
raise Exception("doh")
def bar():
foo()
foo()
```
""",
)
result = testdir.runpytest("--markdown-docs")
result.assert_outcomes(passed=0, failed=1)
# we check the traceback vs a regex pattern since the file paths can change
expected_output_pattern = r"""
Error in code block:
```
4 def foo\(\):
5 raise Exception\("doh"\)
6
7 def bar\(\):
8 foo\(\)
9
10 foo\(\)
```
Traceback \(most recent call last\):
File ".*/test_traceback.md", line 10, in <module>
foo\(\)
File ".*/test_traceback.md", line 5, in foo
raise Exception\("doh"\)
Exception: doh
""".strip()
pytest_output = "\n".join(line.rstrip() for line in result.outlines).strip()
assert re.search(expected_output_pattern, pytest_output) is not None, (
"Output traceback doesn't match expected value"
)
def test_autouse_fixtures(testdir):
testdir.makeconftest(
"""
import pytest
@pytest.fixture(autouse=True)
def initialize():
import pytest_markdown_docs
pytest_markdown_docs.bump = getattr(pytest_markdown_docs, "bump", 0) + 1
yield
pytest_markdown_docs.bump -= 1
"""
)
testdir.makefile(
".md",
"""
```python
import pytest_markdown_docs
assert pytest_markdown_docs.bump == 1
```
""",
)
result = testdir.runpytest("--markdown-docs")
result.assert_outcomes(passed=1)
def test_specific_fixtures(testdir):
testdir.makeconftest(
"""
import pytest
@pytest.fixture()
def initialize_specific():
import pytest_markdown_docs
pytest_markdown_docs.bump = getattr(pytest_markdown_docs, "bump", 0) + 1
yield "foobar"
pytest_markdown_docs.bump -= 1
"""
)
testdir.makefile(
".md",
"""
\"\"\"
```python fixture:initialize_specific
import pytest_markdown_docs
assert pytest_markdown_docs.bump == 1
assert initialize_specific == "foobar"
```
\"\"\"
""",
)
result = testdir.runpytest("--markdown-docs")
result.assert_outcomes(passed=1)
def test_non_existing_fixture_error(testdir):
testdir.makeconftest(
"""
import pytest
@pytest.fixture()
def foo():
pass
"""
)
testdir.makefile(
".md",
"""
\"\"\"
```python fixture:bar
```
\"\"\"
""",
)
result = testdir.runpytest("--markdown-docs")
assert "fixture 'bar' not found" in result.stdout.str()
result.assert_outcomes(errors=1)
def test_fixture_overriding_global(testdir):
testdir.makeconftest(
"""
import pytest
def pytest_markdown_docs_globals():
return {
"some_global": "foo"
}
@pytest.fixture()
def some_global():
return "bar"
"""
)
testdir.makefile(
".md",
"""
\"\"\"
```python
assert some_global == "foo"
```
```python fixture:some_global
assert some_global == "bar"
```
\"\"\"
""",
)
result = testdir.runpytest("--markdown-docs")
result.assert_outcomes(passed=2)
def test_continuation_mdx_comment(testdir):
testdir.makefile(
".mdx",
"""
```python
b = "hello"
```
{/* pmd-metadata: continuation */}
```python
assert b + " world" == "hello world"
```
""",
)
result = testdir.runpytest("--markdown-docs")
result.assert_outcomes(passed=2)
def test_specific_fixture_mdx_comment(testdir):
testdir.makeconftest(
"""
import pytest
@pytest.fixture()
def initialize_specific():
import pytest_markdown_docs
pytest_markdown_docs.bump = getattr(pytest_markdown_docs, "bump", 0) + 1
yield "foobar"
pytest_markdown_docs.bump -= 1
"""
)
testdir.makefile(
".mdx",
"""
{/* pmd-metadata: fixture:initialize_specific */}
```python
import pytest_markdown_docs
assert pytest_markdown_docs.bump == 1
assert initialize_specific == "foobar"
```
""",
)
result = testdir.runpytest("--markdown-docs")
result.assert_outcomes(passed=1)
def test_multiple_fixtures_mdx_comment(testdir):
testdir.makeconftest(
"""
import pytest
@pytest.fixture()
def initialize_specific():
import pytest_markdown_docs
pytest_markdown_docs.bump = getattr(pytest_markdown_docs, "bump", 0) + 1
yield "foobar"
pytest_markdown_docs.bump -= 1
@pytest.fixture
def another_fixture():
return "hello"
"""
)
testdir.makefile(
".mdx",
"""
{/* pmd-metadata: fixture:initialize_specific fixture:another_fixture */}
```python
import pytest_markdown_docs
assert pytest_markdown_docs.bump == 1
assert initialize_specific == "foobar"
```
""",
)
result = testdir.runpytest("--markdown-docs")
result.assert_outcomes(passed=1)
def test_notest_mdx_comment(testdir):
testdir.makefile(
".mdx",
"""
{/* pmd-metadata: notest */}
```python
assert True
```
""",
)
result = testdir.runpytest("--markdown-docs")
result.assert_outcomes(passed=0)
def test_superfences_format_markdown(testdir):
testdir.makefile(
".md",
"""
```python
b = "hello"
```
```{.python continuation}
assert b + " world" == "hello world"
```
# the lang may not be the first element
```{other_option .python .other-class continuation}
assert b + " world" == "hello world"
```
""",
)
result = testdir.runpytest("--markdown-docs", "--markdown-docs-syntax=superfences")
result.assert_outcomes(passed=3)
def test_superfences_format_docstring(testdir):
testdir.makepyfile(
"""
def simple():
\"\"\"
```python
b = "hello"
```
```{.python continuation}
assert b + " world" == "hello world"
```
\"\"\"
"""
)
result = testdir.runpytest("--markdown-docs", "--markdown-docs-syntax=superfences")
result.assert_outcomes(passed=2)
def test_error_origin_after_docstring_traceback(testdir, support_dir):
sample_file = support_dir / "docstring_error_after.py"
testdir.makepyfile(**{sample_file.stem: sample_file.read_text()})
result = testdir.runpytest("-v", "--markdown-docs")
data: LineMatcher = result.stdout
data.re_match_lines(
[
r"Traceback \(most recent call last\):",
r'\s*File ".*/docstring_error_after.py", line 5, in <module>',
r"\s*docstring_error_after.error_after\(\)",
r'\s*File ".*/docstring_error_after.py", line 11, in error_after',
r'\s*raise Exception\("bar"\)',
r"\s*Exception: bar",
],
consecutive=True,
)
def test_error_origin_before_docstring_traceback(testdir, support_dir):
sample_file = support_dir / "docstring_error_before.py"
testdir.makepyfile(**{sample_file.stem: sample_file.read_text()})
result = testdir.runpytest("-v", "--markdown-docs")
data: LineMatcher = result.stdout
data.re_match_lines(
[
r"Traceback \(most recent call last\):",
r'\s*File ".*/docstring_error_before.py", line 9, in <module>',
r"\s*docstring_error_before.error_before\(\)",
r'\s*File ".*/docstring_error_before.py", line 2, in error_before',
r'\s*raise Exception\("foo"\)',
r"\s*Exception: foo",
],
consecutive=True,
)
def test_docstring_line_numbers(testdir):
testdir.makepyfile(
docstring_lines='''
def summary_on_first_line():
"""Summary line.
```python
raise Exception("foo")
```
"""
def raw_docstring():
r"""Matches \\d.
```python
raise Exception("bar")
```"""
'''
)
result = testdir.runpytest("-v", "--markdown-docs")
result.assert_outcomes(failed=2)
result.stdout.re_match_lines(
[
r".*::raw_docstring\[CodeFence#1\]\[line:13\] FAILED.*",
r".*::summary_on_first_line\[CodeFence#1\]\[line:4\] FAILED.*",
],
consecutive=True,
)
result.stdout.re_match_lines(
[
r'\s*File ".*/docstring_lines.py", line 14, in <module>',
r'\s*raise Exception\("bar"\)',
],
consecutive=True,
)
result.stdout.re_match_lines(
[
r'\s*File ".*/docstring_lines.py", line 5, in <module>',
r'\s*raise Exception\("foo"\)',
],
consecutive=True,
)
def test_module_docstring_line_numbers(testdir):
testdir.makepyfile(
module_docstring='''
"""
```python
raise Exception("foo")
```
"""
'''
)
result = testdir.runpytest("-v", "--markdown-docs")
result.assert_outcomes(failed=1)
result.stdout.re_match_lines(
[
r".*::module_docstring\[CodeFence#1\]\[line:2\] FAILED.*",
r'\s*File ".*/module_docstring.py", line 3, in <module>',
]
)
def test_custom_runner(testdir):
testdir.makeconftest(
"""
import pytest_markdown_docs._runners
@pytest_markdown_docs._runners.register_runner()
class LinesAreAllFoo(pytest_markdown_docs._runners.DefaultRunner):
def runtest(self, test, args):
lines = test.source.strip().split("\\n")
for line in lines:
assert line == "foo"
"""
)
testdir.makefile(
".md",
"""
```python runner:LinesAreAllFoo
foo
foo
```
```python runner:LinesAreAllFoo
foo
bar
```
""",
)
result = testdir.runpytest("-v", "--markdown-docs")
result.assert_outcomes(passed=1, failed=1)
result.stdout.re_match_lines(
[
r".*\[CodeFence#1\]\[line:1\].*PASSED.*",
r".*\[CodeFence#2\]\[line:6\].*FAILED.*",
],
consecutive=True,
)
def test_admonition_markdown_text_file(testdir):
testdir.makeconftest(
"""
def pytest_markdown_docs_globals():
return {"a": "hello"}
def pytest_markdown_docs_markdown_it():
import markdown_it
from mdit_py_plugins.admon import admon_plugin
mi = markdown_it.MarkdownIt(config="commonmark")
mi.use(admon_plugin)
return mi
"""
)
testdir.makefile(
".md",
"""
??? quote
```python
assert a + " world" == "hello world"
```
!!! info
```python
assert False
```
???+ note
```python
**@ # this is a syntax error
```
""",
)
result = testdir.runpytest("--markdown-docs")
result.assert_outcomes(passed=1, failed=2)
def test_retry_eventually_succeeds(testdir):
"""Test that a flaky test succeeds after retrying."""
testdir.makepyfile(
conftest="""
attempt_counter = {}
"""
)
testdir.makefile(
".md",
test_file="""
```python retry:3
import conftest
key = "test_1"
conftest.attempt_counter[key] = conftest.attempt_counter.get(key, 0) + 1
assert conftest.attempt_counter[key] >= 2 # Fails first time, passes on retry
```
""",
)
result = testdir.runpytest("--markdown-docs")
result.assert_outcomes(passed=1)
def test_retry_exhausted(testdir):
"""Test that a test fails after all retry attempts are exhausted."""
testdir.makefile(
".md",
test_file="""
```python retry:2
assert False # Always fails
```
""",
)
result = testdir.runpytest("--markdown-docs")
result.assert_outcomes(failed=1)
def test_retry_with_fixture(testdir):
"""Test that fixtures are not re-run between retries."""
testdir.makepyfile(
conftest="""
import pytest
fixture_call_count = 0
@pytest.fixture
def counting_fixture():
global fixture_call_count
fixture_call_count += 1
return fixture_call_count
attempt_counter = {}
"""
)
testdir.makefile(
".md",
test_file="""
```python retry:3 fixture:counting_fixture
import conftest
key = "test_2"
conftest.attempt_counter[key] = conftest.attempt_counter.get(key, 0) + 1
# Fixture should only be called once (value should stay 1)
assert counting_fixture == 1
# Fail on first attempt, pass on second
assert conftest.attempt_counter[key] >= 2
```
""",
)
result = testdir.runpytest("--markdown-docs")
result.assert_outcomes(passed=1)
def test_retry_with_continuation(testdir):
"""Test that retry works with continuation blocks."""
testdir.makepyfile(
conftest="""
attempt_counter = {}
"""
)
testdir.makefile(
".md",
test_file="""
```python
a = "hello"
```
```python retry:2 continuation
import conftest
key = "test_3"
conftest.attempt_counter[key] = conftest.attempt_counter.get(key, 0) + 1
# Variable 'a' from previous block should be available
assert a + " world" == "hello world"
# Fail on first attempt, pass on second
assert conftest.attempt_counter[key] >= 2
```
""",
)
result = testdir.runpytest("--markdown-docs")
result.assert_outcomes(passed=2)
def test_retry_invalid_negative(testdir):
"""Test that negative retry counts raise an error."""
testdir.makefile(
".md",
test_file="""
```python retry:-1
assert True
```
""",
)
result = testdir.runpytest("--markdown-docs")
result.assert_outcomes(errors=1)
result.stdout.fnmatch_lines(["*Invalid retry count*non-negative integer*"])
def test_retry_invalid_non_numeric(testdir):
"""Test that non-numeric retry counts raise an error."""
testdir.makefile(
".md",
test_file="""
```python retry:abc
assert True
```
""",
)
result = testdir.runpytest("--markdown-docs")
result.assert_outcomes(errors=1)
result.stdout.fnmatch_lines(["*Invalid retry count*non-negative integer*"])
def test_retry_multiple_values_error(testdir):
"""Test that multiple retry values raise an error."""
testdir.makefile(
".md",
test_file="""
```python retry:2 retry:3
assert True
```
""",
)
result = testdir.runpytest("--markdown-docs")
result.assert_outcomes(errors=1)
result.stdout.fnmatch_lines(["*Multiple retry counts are not supported*"])
def test_retry_zero(testdir):
"""Test that retry:0 behaves the same as no retry."""
testdir.makefile(
".md",
test_file="""
```python retry:0
assert False
```
""",
)
result = testdir.runpytest("--markdown-docs")
result.assert_outcomes(failed=1)
def test_retry_mdx_comment(testdir):
"""Test that retry works with MDX comment metadata."""
testdir.makepyfile(
conftest="""
attempt_counter = {}
"""
)
testdir.makefile(
".mdx",
test_file="""
{/* pmd-metadata: retry:3 */}
```python
import conftest
key = "test_4"
conftest.attempt_counter[key] = conftest.attempt_counter.get(key, 0) + 1
assert conftest.attempt_counter[key] >= 2
```
""",
)
result = testdir.runpytest("--markdown-docs")
result.assert_outcomes(passed=1)
def test_retry_with_docstring(testdir):
"""Test that retry works in Python docstrings."""
testdir.makepyfile(
conftest="""
attempt_counter = {}
"""
)
testdir.makepyfile(
test_module="""
def my_function():
\"\"\"
```python retry:3
import conftest
key = "test_5"
conftest.attempt_counter[key] = conftest.attempt_counter.get(key, 0) + 1
assert conftest.attempt_counter[key] >= 2
```
\"\"\"
pass
"""
)
result = testdir.runpytest("--markdown-docs")
result.assert_outcomes(passed=1)
# ============================================================================
# Async fixture tests (pytest-asyncio integration)
# ============================================================================
def test_async_fixture_basic(testdir):
"""Test that a basic async fixture works with markdown tests."""
testdir.makeconftest(
"""
import pytest_asyncio
@pytest_asyncio.fixture
async def async_value():
return "async_hello"
"""
)
testdir.makefile(
".md",
test_file="""
```python fixture:async_value
assert async_value == "async_hello"
```
""",
)
result = testdir.runpytest("--markdown-docs", "-v")
result.assert_outcomes(passed=1)
def test_async_fixture_with_await(testdir):
"""Test that an async fixture that uses await works."""
testdir.makeconftest(
"""
import asyncio
import pytest_asyncio
@pytest_asyncio.fixture
async def async_delayed_value():
await asyncio.sleep(0.01)
return "delayed_value"
"""
)
testdir.makefile(
".md",
test_file="""
```python fixture:async_delayed_value
assert async_delayed_value == "delayed_value"
```
""",
)
result = testdir.runpytest("--markdown-docs", "-v")
result.assert_outcomes(passed=1)
def test_async_generator_fixture(testdir):
"""Test that an async generator fixture (with yield) works."""
testdir.makeconftest(
"""
import pytest_asyncio
import pytest_markdown_docs
@pytest_asyncio.fixture
async def async_resource():
# Setup
pytest_markdown_docs.async_setup_called = True
yield "resource_value"
# Teardown
pytest_markdown_docs.async_teardown_called = True
"""
)
testdir.makefile(
".md",
test_file="""
```python fixture:async_resource
import pytest_markdown_docs
assert async_resource == "resource_value"
assert pytest_markdown_docs.async_setup_called == True
```
""",
)
result = testdir.runpytest("--markdown-docs", "-v")
result.assert_outcomes(passed=1)
# Verify teardown was called
assert getattr(pytest_markdown_docs, "async_teardown_called", False) is True
# Clean up
delattr(pytest_markdown_docs, "async_setup_called")
delattr(pytest_markdown_docs, "async_teardown_called")
def test_async_fixture_chain(testdir):
"""Test that an async fixture can depend on another async fixture."""
testdir.makeconftest(
"""
import pytest_asyncio
@pytest_asyncio.fixture
async def base_async_value():
return "base"
@pytest_asyncio.fixture
async def derived_async_value(base_async_value):
return f"{base_async_value}_derived"
"""
)
testdir.makefile(
".md",
test_file="""
```python fixture:derived_async_value
assert derived_async_value == "base_derived"
```
""",
)
result = testdir.runpytest("--markdown-docs", "-v")
result.assert_outcomes(passed=1)
def test_async_fixture_depends_on_sync_fixture(testdir):
"""Test that an async fixture can depend on a sync fixture."""
testdir.makeconftest(
"""
import pytest
import pytest_asyncio
@pytest.fixture
def sync_value():
return "sync"
@pytest_asyncio.fixture
async def async_combined(sync_value):
return f"{sync_value}_async"
"""
)
testdir.makefile(
".md",
test_file="""
```python fixture:async_combined
assert async_combined == "sync_async"
```
""",
)
result = testdir.runpytest("--markdown-docs", "-v")
result.assert_outcomes(passed=1)
def test_sync_fixture_depends_on_async_fixture(testdir):
"""Test that a sync fixture can depend on an async fixture."""
testdir.makeconftest(
"""
import pytest
import pytest_asyncio
@pytest_asyncio.fixture
async def async_base():
return "async"