Skip to Content
Flask Web开发:基于Python的Web应用开发实战(第2版)
book

Flask Web开发:基于Python的Web应用开发实战(第2版)

by Miguel Grinberg
August 2018
Intermediate to advanced
230 pages
6h 42m
Chinese
O'Reilly Media, Inc. Beijing
Content preview from Flask Web开发:基于Python的Web应用开发实战(第2版)
180
15
测试的最后一部分在导航栏中查找“
Profile
”链接,然后点击。为证实资料页已经加载,
测试在页面源码中搜索内容为用户名的标题。
如果你从
GitHub
上克隆了这个应用的
Git
仓库,那么可以执行
git checkout
15d
检出应用的这个版本。这次更新包含一个数据库迁移,所以签出代码后
记得要执行
flask db upgrade
命令。为保证安装了所有依赖,还要执行
pip
install -r requirements/dev.txt
此时执行 flask test 命令,你看不到单元测试的运行有什么差别。示例
15-8
中的单
元测试test_admin_home_page 在无界面
Chrome
实例中运行,并执行所有操作。如
果你想在
Chrome
窗口中查看执行的操作,把setUpClass() 方法中的options.add_
argument('headless') 一行注释掉,让
Selenium
启动带窗口的常规
Chrome
实例。
15.4
 值得测试吗
读到这里你可能会问,为了测试而如此折腾
Flask
测试客户端和
Selenium
,值得吗?这是
一个合理的疑问,但是不容易回答。
不管你是否喜欢,应用肯定要做测试。如果你自己不做测试,用户就要充当不情愿的测试
员,用户发现问题后,你就要顶着压力修正。检查数据库模型和其他无须在应用上下文中
执行的代码很简单,而且有针对性,这类测试一定要做,因为你无须投入过多精力就能保
证应用逻辑的核心功能可以正常运行。
我们有时候也需要使用
Flask
测试客户端和 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Python机器学习基础教程

Python机器学习基础教程

Andreas C. Müller, Sarah Guido
Python编程入门与实战

Python编程入门与实战

Posts & Telecom Press, Fabrizio Romano
程序设计导论:Python语言实践

程序设计导论:Python语言实践

罗伯特 塞奇威克, 凯文 韦恩, 罗伯特 唐德罗

Publisher Resources

ISBN: 9787115489456