import pytest import json from tinydb import TinyDB @pytest.fixture def db(): db = TinyDB("db.json") print("\n Setup DB") yield db #db.purge() print("/n Teardown DB") de...
Python
Python3 yield使用总结
示例 import scrapy class QuotesSpider(scrapy.Spider): name = "quotes def start_requests(self): urls = [ 'http://quotes.toscrape.com/page/1/', 'ht...
pytest 4 @pytest.fixture运用2
test_people.py from test_case.people import Person, anyone_like_dogs import pytest @pytest.fixture() def person(): return Person(name = "Bob", favorite_animal = "dog") def test_anyone_l...
pytest 3 @mock.patch的运用
本案例使用了一个随机数加上变量实现测试出现随机的结果,暂时初略看过,需要再深入学习的内容 test_dnd.py from test_case.dnd import attack_damage from unittest import mock @mock.patch("dnd.randi...
Pytest 2 @pytest.fixture运用及对map结果的渐进测试方法
1、单文件实现效果 def greet(person): return "Hi {name}".format(**person) def test_greet(): bob = {"name":"Bob"} #Arrange greeting = greet(bob) #Act assert greeting == "Hi Bob...
Pytest 1 测试原理
1、定义测试文件、类、方法 2、定义assert关键字做运行结果与期待结果做比较 3、执行pytest def test_pass(): assert 1 + 1 == 2
Pytest-安装&运行
一、安装 1)新建项目,在PyCharm上进行安装pytest即可 2)两种安装方式,目测第二种比较受用 pip install-U pytest pip3 install pytest -i http://pypi.douban.com/simple/ --trusted-host p...
高考分数爬到503的解决方法
重点:当遭遇503错误的时候多数是因为headers错误,出了User-Agent再加一个Accept-Encoding就可以了 import requests url="https://api.eol.cn/gkcx/api/?access_token=&page=1&province_id=33&s...
爬虫 6 selenium调动浏览器爬数据
# 以下方法都可以从网页中提取出'你好,蜘蛛侠!'这段文字 find_element_by_tag_name:通过元素的名称选择 # 如<h1>你好,蜘蛛侠!</h1> # 可以使用find_element_by_tag_name('h1') find_element_b...
json 模块的使用
import requests, json url = 'http://ictclas.nlpir.org/nlpir/index6/getWord2Vec.do' headers={'origin':'http://ictclas.nlpir.org', 'referer':'http://ictclas.nlpir.org/nlpir/', 'user-agent':'...