Skip to content

Commit 56e340d

Browse files
authored
Merge pull request RustPython#2530 from verhovsky/redirect-stdout-in-whats_left
remove noise from importing modules in whats_left
2 parents 163cd19 + 3592c74 commit 56e340d

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

extra_tests/not_impl_gen.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@
77
# cpymods - a dictionary mapping module names to their contents
88
# libdir - the location of RustPython's Lib/ directory.
99

10-
import re
10+
import inspect
11+
import io
1112
import os
13+
import re
1214
import sys
1315
import warnings
14-
import inspect
16+
from contextlib import redirect_stdout
1517
from pydoc import ModuleScanner
1618

1719

@@ -138,7 +140,10 @@ def onerror(modname):
138140

139141

140142
def dir_of_mod_or_error(module_name):
141-
with warnings.catch_warnings():
143+
# Importing modules causes ('Constant String', 2, None, 4) and
144+
# "Hello world!" to be printed to stdout.
145+
f = io.StringIO()
146+
with warnings.catch_warnings(), redirect_stdout(f):
142147
# ignore warnings caused by importing deprecated modules
143148
warnings.filterwarnings("ignore", category=DeprecationWarning)
144149
try:
@@ -197,11 +202,14 @@ def gen_modules():
197202
libdir = ""
198203
# This function holds the source code that will be run under RustPython
199204
def compare():
200-
import re
205+
import inspect
206+
import io
201207
import os
208+
import re
202209
import sys
203210
import warnings
204-
import inspect
211+
from contextlib import redirect_stdout
212+
205213
import platform
206214

207215
def method_incompatability_reason(typ, method_name, real_method_value):

0 commit comments

Comments
 (0)