Giter Club home page Giter Club logo

python-ut's Introduction

Python单元测试示例

一、简介

1. 项目介绍

一个简单的博客系统,包含:

  • 创建文章
  • 获取文章
  • 获取文章列表

2. 关键技术

  • Flask,web框架
  • SQLite,数据库
  • pytest,单元测试框架
  • pydantic,数据校验

二、运行

1. 根据requirements.txt安装对应依赖

pip3 install -r requirements.txt

2. 初始化数据库

python3 src/blog/init_db.py

3. 本地运行

直接在IDE运行,或者通过命令FLASK_APP=blog/app.py python3 -m flask run运行:

$ FLASK_APP=src/blog/app.py python3 -m flask run
 * Serving Flask app "src/blog/app.py"
 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: off
 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)

访问网站http://localhost:5000/article-list/

4. 运行测试

python3 -m pytest src/tests

$ python3 -m pytest src/tests
================================================================= test session starts ==================================================================
platform darwin -- Python 3.8.3, pytest-6.2.2, py-1.10.0, pluggy-0.13.1
rootdir: /Users/yukki/Downloads/Project/python-ut
plugins: metadata-1.11.0, html-3.1.1
collected 11 items                                                                                                                                     

src/tests/blog/test_app.py ......                                                                                                                [ 54%]
src/tests/blog/test_commands.py ...                                                                                                              [ 81%]
src/tests/blog/test_queries.py ..                                                                                                                [100%]

================================================================== 11 passed in 0.18s ==================================================================

参考

python-ut's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.