44
44
running_in_ci , running_in_ci_with_conda )
45
45
from spyder .config .gui import get_color_scheme
46
46
from spyder .config .manager import CONF
47
+ from spyder .config .utils import is_anaconda
47
48
from spyder .py3compat import PY2 , to_text_string
48
49
from spyder .plugins .help .tests .test_plugin import check_text
49
50
from spyder .plugins .help .utils .sphinxify import CSS_PATH
50
51
from spyder .plugins .ipythonconsole .plugin import IPythonConsole
51
52
from spyder .plugins .ipythonconsole .utils .style import create_style_class
52
53
from spyder .plugins .ipythonconsole .widgets import ClientWidget
53
54
from spyder .utils .programs import get_temp_dir
54
- from spyder .utils .conda import is_conda_env
55
+ from spyder .utils .conda import get_conda_root_prefix
55
56
56
57
57
58
# =============================================================================
@@ -78,8 +79,11 @@ def get_console_background_color(style_sheet):
78
79
return background_color
79
80
80
81
81
- def get_conda_test_env (test_env_name = u'spytest-ž' ):
82
- """Return the full prefix path of the given `test_env_name`."""
82
+ def get_conda_test_env (test_env_name = 'spytest-ž' ):
83
+ """
84
+ Return the full prefix path of the given `test_env_name` and its
85
+ executable.
86
+ """
83
87
if 'envs' in sys .prefix :
84
88
root_prefix = os .path .dirname (os .path .dirname (sys .prefix ))
85
89
else :
@@ -92,7 +96,7 @@ def get_conda_test_env(test_env_name=u'spytest-ž'):
92
96
else :
93
97
test_env_executable = os .path .join (test_env_prefix , 'bin' , 'python' )
94
98
95
- return test_env_executable
99
+ return ( test_env_prefix , test_env_executable )
96
100
97
101
98
102
# =============================================================================
@@ -196,7 +200,7 @@ def __getattr__(self, attr):
196
200
if test_environment_interpreter :
197
201
configuration .set ('main_interpreter' , 'default' , False )
198
202
configuration .set (
199
- 'main_interpreter' , 'executable' , get_conda_test_env ())
203
+ 'main_interpreter' , 'executable' , get_conda_test_env ()[ 1 ] )
200
204
else :
201
205
configuration .set ('main_interpreter' , 'default' , True )
202
206
configuration .set ('main_interpreter' , 'executable' , '' )
@@ -1657,6 +1661,8 @@ def test_calltip(ipyconsole, qtbot):
1657
1661
@flaky (max_runs = 3 )
1658
1662
@pytest .mark .order (1 )
1659
1663
@pytest .mark .test_environment_interpreter
1664
+ @pytest .mark .skipif (not is_anaconda (), reason = 'Only works with Anaconda' )
1665
+ @pytest .mark .skipif (not running_in_ci (), reason = 'Only works on CIs' )
1660
1666
def test_conda_env_activation (ipyconsole , qtbot ):
1661
1667
"""
1662
1668
Test that the conda environment associated with an external interpreter
@@ -1668,12 +1674,12 @@ def test_conda_env_activation(ipyconsole, qtbot):
1668
1674
# Get conda activation environment variable
1669
1675
with qtbot .waitSignal (shell .executed ):
1670
1676
shell .execute (
1671
- "import os; conda_prefix = os.environ.get('CONDA_PREFIX')" )
1677
+ "import os; conda_prefix = os.environ.get('CONDA_PREFIX')"
1678
+ )
1672
1679
1673
- expected_output = get_conda_test_env ().replace ('\\ ' , '/' )
1674
- if is_conda_env (expected_output ):
1675
- output = shell .get_value ('conda_prefix' ).replace ('\\ ' , '/' )
1676
- assert expected_output == output
1680
+ expected_output = get_conda_test_env ()[0 ].replace ('\\ ' , '/' )
1681
+ output = shell .get_value ('conda_prefix' ).replace ('\\ ' , '/' )
1682
+ assert expected_output == output
1677
1683
1678
1684
1679
1685
@flaky (max_runs = 3 )
@@ -2438,8 +2444,7 @@ def test_run_script(ipyconsole, qtbot, tmp_path):
2438
2444
2439
2445
2440
2446
@pytest .mark .skipif (
2441
- not sys .platform .startswith ('linux' ),
2442
- reason = "Only runs on Linux" )
2447
+ not is_anaconda (), reason = "Only works with Anaconda" )
2443
2448
def test_show_spyder_kernels_error_on_restart (ipyconsole , qtbot ):
2444
2449
"""Test that we show Spyder-kernels error message on restarts."""
2445
2450
# Wait until the window is fully up
@@ -2449,11 +2454,13 @@ def test_show_spyder_kernels_error_on_restart(ipyconsole, qtbot):
2449
2454
2450
2455
# Point to an interpreter without Spyder-kernels
2451
2456
ipyconsole .set_conf ('default' , False , section = 'main_interpreter' )
2452
- ipyconsole .set_conf ('executable' , '/usr/bin/python3' ,
2453
- section = 'main_interpreter' )
2457
+ if os .name == 'nt' :
2458
+ pyexec = osp .join (get_conda_root_prefix (), 'python.exe' )
2459
+ else :
2460
+ pyexec = osp .join (get_conda_root_prefix (), 'bin' , 'python' )
2461
+ ipyconsole .set_conf ('executable' , pyexec , section = 'main_interpreter' )
2454
2462
2455
2463
# Restart kernel
2456
- os .environ ['SPY_TEST_SHOW_RESTART_MESSAGE' ] = 'true'
2457
2464
ipyconsole .restart_kernel ()
2458
2465
2459
2466
# Assert we show a kernel error
@@ -2467,7 +2474,7 @@ def test_show_spyder_kernels_error_on_restart(ipyconsole, qtbot):
2467
2474
timeout = 6000
2468
2475
)
2469
2476
2470
- # To check kernel error visually
2477
+ # To check the kernel error visually
2471
2478
qtbot .wait (500 )
2472
2479
2473
2480
# Check kernel related actions are disabled
0 commit comments