Git Product home page Git Product logo

flask-pytest-example's Introduction

Flask Pytest routing and requests example

Simple sample application demonstrating how to use Pytest with Flask for testing routing and requests. The example includes a basic "hello world" route to demonstrate a GET request. The second example is a route that expects a POST request.

Setup and run instructions

Install the requirements into a virtualenv or your environment of choice

pip install -r requirements.txt

which includes

  • flask
  • pytest

then run the pytest command

flask-pytest-example's People

Contributors

aaronjolson avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

flask-pytest-example's Issues

Pytest Fails

=========================================== test session starts ============================================
platform linux -- Python 3.8.5, pytest-6.2.4, py-1.10.0, pluggy-0.13.1
rootdir: /home/danwand/work/bfh/flask-pytest-example
plugins: flask-1.2.0, requests-mock-1.8.0
collected 0 items / 1 error                                                                                

================================================== ERRORS ==================================================
__________________________________ ERROR collecting tests/test_routes.py ___________________________________
ImportError while importing test module '/home/danwand/work/bfh/flask-pytest-example/tests/test_routes.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/usr/lib/python3.8/importlib/__init__.py:127: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
tests/test_routes.py:4: in <module>
    from flask_pytest_example.handlers.routes import configure_routes
E   ModuleNotFoundError: No module named 'flask_pytest_example'
========================================= short test summary info ==========================================
ERROR tests/test_routes.py
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
============================================= 1 error in 0.08s =============================================

`pytest` fails with ModuleNotFoundError

Running pytest from the root directory does not work as advertised.

145@145-xps:~/git/flask-pytest-example$ pytest
============================================ test session starts =============================================
platform linux -- Python 3.6.9, pytest-6.2.2, py-1.10.0, pluggy-0.13.1
rootdir: /home/145/git/flask-pytest-example
collected 0 items / 1 error                                                                                  

=================================================== ERRORS ===================================================
___________________________________ ERROR collecting tests/test_routes.py ____________________________________
ImportError while importing test module '/home/145/git/flask-pytest-example/tests/test_routes.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/usr/lib/python3.6/importlib/__init__.py:126: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
tests/test_routes.py:4: in <module>
    from flask_pytest_example.handlers.routes import configure_routes
E   ModuleNotFoundError: No module named 'flask_pytest_example'
========================================== short test summary info ===========================================
ERROR tests/test_routes.py
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
============================================== 1 error in 0.17s ==============================================

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.