简体   繁体   中英

Strange Python package import behavior in Visual Studio

I encountered a very strange behavior of Python project in VS 2017. Suppose, I have a "library" Python project and also a unit testing project. When I add the following lines

import unittest
import Metric.metric as metr    // module from the first project

into file in the second project it works fine (I even can press F12 on 'unitests' and go to __init_ file of unittest framework, or on 'metr' and see contents of metric.py file) but only until VS reload . After reloading the second line no longer works!!! The first line may work but just for a while. After some time (and may be another VS reload) it also breaks down - neither F12 nor unit test discovery not working

Moreover, after I type 'import' and press Ctrl+Space, a 'unittest' hint string also no longer available in IntelliSence popup!

What may be the reason of such a strange problem? I also tried to reproduce it on another toy example with no success - everything works as expected! So you may also be not able to reproduce the problem. The only hope is for someone's intuition.

My settings (all up-to-date):

Visual Studio 2017 15.5.2

Environment - Python 3.6 (64 bit) (global default)

python中的注释使用#代替//

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM