Pycharm - no tests were found?

后端 未结 8 2099
鱼传尺愫
鱼传尺愫 2020-12-18 17:52

I\'ve been getting a

No tests were found

error in Pycharm and I can\'t figure out why I\'m getting it... this is what I have f

8条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-18 18:19

    I had this exception when running individual tests in a Django 1.8 project in PyCharm 2018.1. I could run all the tests together, but individual tests in one file crashed.

    The exception was happening in unittest's loader.py

    It was getting an ImportError trying to import test_admin_views.py, though the exception was hiding the details of that error.

    To see the details of the ImportError, I opened a Python Console and ran:

    import my_app.users.tests.test_admin_views
    

    This gave me:

    Traceback (most recent call last):
      [...]
      File "my_app/my_app/users/tests/model_factories.py", line 42, in 
        from my_app.applications.tests.model_factories import ApplicationFactory
    ImportError: cannot import name ApplicationFactory
    

    I noticed that some of the other factories in that file are imported without using the full path, so I tried adding ApplicationFactory to the relative path import list:

    from .model_factories import UserFactory, UserGroupFactory, ApplicationFactory
    

    Which worked!

提交回复
热议问题