-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path39.py
More file actions
25 lines (21 loc) · 938 Bytes
/
Copy path39.py
File metadata and controls
25 lines (21 loc) · 938 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
from urllib.request import urlopen
from bs4 import BeautifulSoup
import unittest
#需要注意的是,这个页面的内容只运行一次,全局对象bsobj由多个测试共享
#setupClass只在类的初始化阶段运行一次,用setupclass代替setup可以省去不必要的页面加载,我们可以一次性采集全部内容,供多个测试使用
class TestWikipedia(unittest.TestCase):
bsObj = None
def setUpClass():
global bsObj
url = "http://en.wikipedia.org/wiki/Monty_Python"
bsObj =BeautifulSoup(urlopen(url))
def test_titleText(self):
global bsObj
pageTitle = bsObj.find("h1").get_text()
self.assertEqual("Monty Python",pageTitle)
def test_contentExists(self):
global bsObj
content =bsObj.find("div",{'id':'mw-content-text'})
self.assertIsNotNone(content)
if __name__=='__main__':
unittest.main()