py.test tests fail in 2017.1 due to runner current directory

It seems that new test runner for PyCharm 2017.1 changed default behavior comparing to previous releases. When running py.test tests using PyCharm generated run configuration all tests were run inside project test directory. In 2017 py.test runs in project root (just like being called from command line). The previous behavior broke some CI systems defaults that expected py.test standard behavior. 

Now it breaks all our test configs generated by previous PyCharm versions. It also seems to be ignoring py.test path setting in run configuration making it all pretty useless for running test suite. 

17 comments
Official comment

Hello.

Indeed the logic PyCharm used to find working directory been changed in 2017.1 leading to several bugs. It is now fixed and should be available in 2017.1.2 in couple of days. Please try 2017.1.2, and contact support (pycharm-support@jetbrains.com) for instructions on how to switch back to old runners if something still would not work with new release. 

 

I am also facing similar problem with PyCharm 2017.1.Do you have any workaround?

Going back to PyCharm 2016

0

The only solution right now we've found - mind you we did not look deeply into this one - after identifying the problem was to run tests manually using py.test from command line. Since our CI pipeline is running all the tests anyway we switched it to it for a day. If this ain't going to be fixed quickly or a simple workaround is found we will switch to 2016 just like you did.

As a side note: I find it funny that with all that TDD in place it was a bug (unless it is a feature of new) test runner that slipped through QA process.

0

Yeah, I am totally having the same problem. All of a sudden all of my test cases don't work any more. Talk about killing my productivity today. 

0

I'm having a similar issue, which might be related. The wrong test file was selected.

I wanted to run a test in the TestSyncDeletedDomains class, in the tests/integration/actions/test_domain.py file, but the pycharm test runner outputs:

ERROR: file not found: tests/integration/actions.py::test_domain::TestSyncDeletedDomains

This can be fixed with the following patch:

--- _jb_runner_tools.py.orig 2017-03-28 23:27:33.000000000 +0200
+++ _jb_runner_tools.py 2017-03-28 23:26:40.000000000 +0200
@@ -359,8 +359,8 @@
try:
splitter.check_is_importable(parts, i, separator)
except ImportError:
- fs_part = fs_glue.join(parts[:i])
- python_path = python_glue.join(parts[i:])
+ fs_part = fs_glue.join(parts[:i+1])
+ python_path = python_glue.join(parts[i+1:])
return fs_part + fs_to_python_glue + python_path if python_path else fs_part
return target

Apply like this (change paths accordingly):

sudo patch -p0 /home/vagrant/.pycharm_helpers/pycharm/_jb_runner_tools.py pycharm-pytest-fixup.patch

Revert like this:

sudo patch -p0 -R /home/vagrant/.pycharm_helpers/pycharm/_jb_runner_tools.py pycharm-pytest-fixup.patch

@JetBrains: Please fix this properly.

1

Also seeing this! The patch from tgwizard works, although the line numbers doesn't match exactly in my version of _jb_runner_tools.py.

Should this be reported on some issue tracker instead?

0

I've already reported the issue and opened ticket in bug tracker: https://youtrack.jetbrains.com/issue/PY-23303  

0

Just wanted to chime in that I too had this issue, and @Tgwizard's fix solved it for me as well. Thanks!

0

@Tgwizard I have the same problem. Thanks for the fix - I'll try it out.

0

Me too. Been a while since upgrading PC did NOT break something vital . . . 

1

This is extremely painful to deal with.  I can no longer run ANY pytest in this version unless I invoke the command manually. 

1

Updating to version PyCharm 2017.1.1 (Build #PY-171.4163.6, built on April 11, 2017) completely broke comfortable possibility to run test using right click menu.

It always runs the test using python and not py.test now.

Please, return previous behaviour - it was VERY useful.

1

Yeah I tried the new version of pycharm 2017.1 171.4163 yesterday and pytest still cannot find my test cases. I can't tell if the test discovery problem comes from the band-aids I had to put in place when this whole thing began or if there is some exotic setting that I am missing. This is really frustrating.

Don't get me wrong, I understand the jetbrains folks are trying their best to fix it and I appreciate that. So keep up the good work. The challenge is that this is costing me a lot of productivity.

 

2

I seem to be experiencing the same problem in IntelliJ through the Python plugin

0

Guess what - it's broken again in 2017.2.

I haven't worked out how to fix it yet though . . . .

Not impressed!

[EDIT] selected path option, deleted existing path, selected full path

0

Still seems broken here as well.

Running as pytest, I cannot find ZODB.FileSystem.   Running the same file within PyCharm does find it.

Could this be put on the "Derailing commercial licenses for more than six months" queue?

===

Build 172.3968.37, PyCharm Commerical

Pytest line is currently:

/Users/cmerriam/l/miniconda2/envs/nike/bin/python /Applications/PyCharm.app/Contents/helpers/pycharm/_jb_pytest_runner.py --path /Users/cmerriam/p/nike/static

Error is:

import ZODB.FileStorage
ImportError: No module named FileStorage

 

ZODB is in the site-packages directory

$ ls -ld ZODB*
drwxr-xr-x 4 ... 136 Aug 31 16:47 ZODB-5.2.4-py2.7.egg/
-rw-r--r-- 1 ... 23 Aug 31 16:47 ZODB.pth

.../python2.7/site-packages
$ cat ZODB.pth
./ZODB-5.2.4-py2.7.egg


$ ls ZODB-5.2.4-py2.7.egg/
EGG-INFO/ ZODB/


$ ls -d ZODB-5.2.4-py2.7.egg/ZODB/F*
ZODB-5.2.4-py2.7.egg/ZODB/FileStorage/

 

 

0

Hello.

Please create issue in issue tracker: http://youtrack.jetbrains.com and provide project to reproduce if possible.

0

Please sign in to leave a comment.