-
-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix test_pytestrunner_start #150
Fix test_pytestrunner_start #150
Conversation
by patching add_pathlist_to_PYTHONPATH. This function first checks whether PYTHONPATH is set in the actual (!) OS environment and then changes the passed in env list by either setting or prepending the pathlist to PYTHONPATH. The test failed if the OS environment in that the test is run hasn't set PYTHONPATH as in the test, we call add_pathlist_to_PYTHONPATH with an env list where PYTHONPATH is already set.
26d34d1
to
80defd9
Compare
@jitseniesen I suggest reviewing/merging this PR only after #151 in order to avoid the need for rebasing as both this and #151 are based on the same commit. |
Thanks for looking into this. I asked what In case we don't get clarification on what the function is supposed to do, perhaps we should not rely on it in our plugin and instead write code ourselves to add the PYTHONPATH to the environment; what do you think? |
Yes, this was my thought too. I'd get rid of this function and replace it by a more elegant solution. I'll prepare a PR shortly. (I just took care of it because of the TODO comment). |
- simplify the way pythonpath is inserted into the process environment - get rid of external dependency add_pathlist_to_PYTHONPATH - follow advice at doc.qt.io/qt-5/qprocessenvironment.html#toStringList to not use the list obtained from toStringList with setEnvironment - it must be `if pythonpath` instead of `if pythonpath is not None` as pythonpath is a list and if it's empty it's still not None so we would insert a variable PYTHONPATH without a value into the environment
pythonpath must be a list of strings, not a string
test_pytestrunner_start was rather complex and tested not only start itself but also create_argument_list as well as _prepare_process and start of the base class. This was split into four separate unit tests for the involved pytestrunner and runnerbase functions.
Refactor _prepare_process
Fix
|
Me too! That is probably why I ended up with the monster test; sorry about that. So the code is actually simpler when not using add_pathlist_to_PYTHONPATH, nice! One question, since you got rid of If you don't want to be bothered about Python 2, that is fine with me; I'm also tired of it. But I don't want to break Python 2 in between versions 0.4.0 and 0.4.1 of the plugin, so I will then postpone this PR to version 0.5 of the plugin. Since there should not be any user-visible changes, that is not a big deal for me, but it does mean that it will take longer before your changes make their way to the users. |
Hmm, how can I test this? Just by running the tests from python 2 or do I need to actually run spyder with the plugin from python 2. If the latter then how can I do that? I guess I need to use test cases where As for the code: env = QProcessEnvironment.systemEnvironment()
old_python_path = env.value('PYTHONPATH', None)
python_path_str = os.pathsep.join(pythonpath)
if old_python_path:
python_path_str += os.pathsep + old_python_path
env.insert('PYTHONPATH', python_path_str) My understanding is that with API 2 ( |
In order to test on python 2.7 I tried to install spyder (via pip) and it failed with the following:
If I understand it correctly it has a requirement of python_path_str = to_text_string(os.pathsep.join(pythonpath)) What do you think? |
I installed a Python 2 environment and found out that the plugin does not work in Python 2 anymore because PR #146 uses Since I can't be bothered to backport that PR and I don't want to ask you to do so, I decided that the next version of the plugin will be Python 3 only which means you don't need to make any changes. Sorry for making you jump through the hoops. |
Thanks! There seem to be several ways to implement nonlocal variables in python 2, but dropping support for python 2 makes things certainly easier. |
by patching
add_pathlist_to_PYTHONPATH
. This function first checks whetherPYTHONPATH
is set in the actual (!) OS environment and then changes the passed-inenv
list by either setting or prepending thepathlist
toPYTHONPATH
. The test failed if the OS environment in that the test is run hasn't setPYTHONPATH
, as in the test, we calladd_pathlist_to_PYTHONPATH
with anenv
list wherePYTHONPATH
is already set.I'm not sure if this isn't a logic flaw in
add_pathlist_to_PYTHONPATH
: I think ifipyconsole
isFalse
it should look forPYTHONPATH
not in the actual OS environment but in the passed-inenv
list. This doesn't play any role in the production code in the unittest plugin as we calladd_pathlist_to_PYTHONPATH
almost immediately after creating the new process, so its inherited environment will almost certainly correspond to the actual environment at the moment whenadd_pathlist_to_PYTHONPATH
is being called .