Pycharm - no tests were found?

后端 未结 8 2022
鱼传尺愫
鱼传尺愫 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:17

    Another issue you may want to check is if you see in the console output "## tests deselected by '-k XXXX'". This means you've added a Keyword to the Run/Debug Configuration, and Pycharm will only run tests whose name contains the keyword.

    0 讨论(0)
  • 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 <module>
        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!

    0 讨论(0)
  • 2020-12-18 18:20

    Don't use dashes ("-") in your filename. These files were being ignored on my machine. renaming them from project-tests.py to project_tests.py solved the problem.

    0 讨论(0)
  • 2020-12-18 18:22

    Another gotcha that has just bitten me.

    I had a test file within my test package called test_queue.py which followed all of the above advice, however when I selected "Run UnitTests" in PyCharm the console reported no tests found.

    The issue in my case was that I had a non-unit test file in the root of the project also called test_queue.py which had been used for some other purpose early on in the project and forgotten about.

    Even though I was specifically selecting the test file in my tests folder, and the path was set to absolutely point at the unit test version of the file, it seems the file in the root of the project was being used.

    So, one more thing to check, make sure there are no other files in your project with the same name.

    0 讨论(0)
  • 2020-12-18 18:27

    Adding another answer in the hopes that it helps someone down the road. I've been fighting this problem and just figured out the answer (I think). I originally deleted the standard Django file tests.py out of my application folder. I also created a subdirectory of my project called tests, which contains separate test scripts. In this situation, Pycharm failed to find the tests. I corrected this simply by creating an empty file called tests.py in my application folder.

    So:

    1. Make sure you have a file called tests.py in your application director (it can be an empty file)
    2. It seems that a folder called tests, in your project, can contain separate test scripts and Pycharm seems to find and run these.

    Here's a picture of the directory structure that's working for me:

    0 讨论(0)
  • 2020-12-18 18:29

    in order to recognize test functions they must be named test_ in your case rename xyCheck to test_xyCheck :)

    0 讨论(0)
提交回复
热议问题