Skip to content

Commit f51432e

Browse files
committed
tests: enforce lazy markdown_it import
1 parent 56e221d commit f51432e

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

tests/test_performance.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import subprocess
2+
import sys
3+
4+
import pytest
5+
6+
7+
def test_importtime__no_mdit_import():
8+
"""Test that `markdown_it` isn't imported when `mdformat` and
9+
`mdformat._cli` are.
10+
11+
Do this in a subprocess to have a clean environment separate from
12+
pytest and other tests.
13+
"""
14+
test_script = """\
15+
import sys
16+
import mdformat
17+
import mdformat._cli
18+
assert 'markdown_it' not in sys.modules, 'markdown_it was imported'
19+
"""
20+
result = subprocess.run(
21+
[sys.executable, "-c", test_script],
22+
stdin=subprocess.DEVNULL,
23+
stderr=subprocess.PIPE,
24+
)
25+
if result.returncode:
26+
assert (
27+
b"markdown_it was imported" in result.stderr
28+
), "unexpected error in subprocess"
29+
pytest.fail("markdown_it was imported")

0 commit comments

Comments
 (0)