You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

首次运行PyCharm ChromeDriver测试求助:unittest执行0个测试用例

Troubleshooting "Ran 0 tests" in Python 2.7 Unittest with Selenium

Hey there! Let's dig into why your unittest suite is reporting "Ran 0 tests in 0.000s OK" even though you've got Python 2.7.10, Selenium 3.5.9, and PyCharm all configured. Here are the most common culprits and fixes to check:

  • Your test class doesn't inherit from unittest.TestCase

    The unittest framework only recognizes classes that subclass unittest.TestCase as test classes. If your class is missing this inheritance, the runner won't pick it up. Double-check your class definition:

    import unittest
    from selenium import webdriver
    
    # Correct: inherits from unittest.TestCase
    class CompanySiteTests(unittest.TestCase):
        def setUp(self):
            self.driver = webdriver.Firefox()  # Or your preferred browser driver
    
        # Test methods go here
    
  • Your test methods don't start with test_

    Unittest only runs methods whose names start with test_ — this is a strict naming convention. If your method names don't follow this, they'll be ignored:

    # This will be recognized as a test
    def test_login_flow(self):
        self.driver.get("https://your-company-site.com/login")
        # ... test logic here
    
    # This WON'T be recognized (wrong prefix)
    def login_test(self):
        # ... logic here
    
  • You're not invoking the test runner

    If you don't tell unittest to run your tests, it won't! Add this block at the very bottom of your test file to trigger the runner when you execute the script:

    if __name__ == '__main__':
        unittest.main()
    
  • PyCharm run configuration glitches

    Sometimes PyCharm doesn't auto-detect tests properly. Try these quick fixes:

    • Right-click your test file in the project explorer and select Run 'Unittest in [your-file-name.py]' — this forces PyCharm to use the correct runner for that file.
    • Go to Run > Edit Configurations and verify the configuration is set to "Unittest", pointing to your test file or class, and using your configured Python 2.7.10 interpreter.
    • Refresh your project (right-click the project root > Refresh) to make sure PyCharm picks up any changes to your test structure.

If you share a snippet of your actual test code, we can narrow this down even further!

内容的提问来源于stack exchange,提问作者dsmith

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 08:16:36