test_example.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. # tests/test_example.py
  2. import pytest
  3. import time
  4. class TestExample:
  5. """示例测试类"""
  6. def test_addition(self):
  7. """测试加法运算"""
  8. assert 1 + 1 == 2
  9. def test_subtraction(self):
  10. """测试减法运算"""
  11. assert 5 - 3 == 2
  12. def test_failure_example(self):
  13. """这是一个会失败的测试示例"""
  14. assert 5 == 6, "数字不相等"
  15. @pytest.mark.skip(reason="示例跳过测试")
  16. def test_skip_example(self):
  17. """这是一个跳过的测试示例"""
  18. assert True
  19. class TestWebExample:
  20. """Web 测试示例"""
  21. def test_web_title(self, driver):
  22. """测试网页标题"""
  23. driver.get("https://baidu.com")
  24. assert "Example" in driver.title
  25. def test_web_content(self, driver):
  26. """测试网页内容"""
  27. driver.get("https://baidu.com")
  28. content = driver.find_element_by_tag_name("body").text
  29. assert "example" in content.lower()
  30. def test_chinese_content(self):
  31. """测试中文字符"""
  32. chinese_text = "这是一段中文测试文本"
  33. assert "中文" in chinese_text