Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pycharm import RuntimeWarning after updating to 2016.2

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.

like image 569
allenlin1992 Avatar asked Jul 25 '16 14:07

allenlin1992


People also ask

How do I fix imports in PyCharm?

To optimize imports in a file, you can also press Ctrl+Alt+Shift+L , select Optimize imports, and click Run.

How do I add imports in PyCharm?

PyCharm can do both. Type the name of the package and hit Alt-Enter , then choose Install and Import package . PyCharm will do both: you'll see a notification during the installation, then the import will be generated in the right way, according to your project styles.


2 Answers

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.

like image 142
Bobby Avatar answered Oct 08 '22 12:10

Bobby


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

from __future__ import absolute_import 
like image 22
Brent Washburne Avatar answered Oct 08 '22 11:10

Brent Washburne