Pycharm import RuntimeWarning after updating to 2016.2

PythonImportPycharm

Python Problem Overview


After updating to new version 2016.2, I am getting

RuntimeWarning: Parent module 'tests' not found while handling absolute import
  import unittest
RuntimeWarning: Parent module 'tests' not found while handling absolute import
  import datetime as dt

'tests' is a package inside my main app package, and I receive these warnings when I try to execute unit tests inside this folder. This issue only came up after updating to 2016.2. Besides the warnings, the remaining code works fine.

Edit: This is a known issue - https://youtrack.jetbrains.com/issue/PY-20171. They are suggesting to replace utrunner.py in PyCharm installation folder.

Python Solutions


Solution 1 - Python

This is a known issue introduced with the 2016.2 release. Progress can be followed on the JetBrains website here. According to this page it is due to be fixed in the 2017.1 release. You can follow the utrunner.py workaround that others have mentioned in the meantime - a copy of this file is attached to the linked ticket.

Solution 2 - Python

The latest recommendation (Dec. 19, 2016) is to put this line at the top of your unit test script:

from __future__ import absolute_import

Solution 3 - Python

On OS X I've fixed this by replacing

Applications/PyCharm.app/Contents/helpers/pycharm/utrunner.py 

with an older version that can be found at http://code.metager.de/source/xref/jetbrains/intellij/community/python/helpers/pycharm/utrunner.py

Solution 4 - Python

On Ubuntu 16.04 Bobby's solution also works:

Just replace your local utrunner.py file at

/usr/local/pycharm-edu-3.0/helpers/pycharm/utrunner.py

by the one from the Jetbrains website: http://code.metager.de/source/xref/jetbrains/intellij/community/python/helpers/pycharm/utrunner.py

Solution 5 - Python

On Windows 10 Bobby's solution also works:

Just replace your local utrunner.py file at

C:\Program Files (x86)\JetBrains\PyCharm 2016.3\helpers\pycharm

with the one from the Jetbrains website: http://code.metager.de/source/xref/jetbrains/intellij/community/python/helpers/pycharm/utrunner.py

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionallenlin1992View Question on Stackoverflow
Solution 1 - PythonBobbyView Answer on Stackoverflow
Solution 2 - PythonBrent WashburneView Answer on Stackoverflow
Solution 3 - PythonmircealunguView Answer on Stackoverflow
Solution 4 - PythonpetibonumView Answer on Stackoverflow
Solution 5 - PythonnidkilView Answer on Stackoverflow