Giter Club home page Giter Club logo

pytest-okken-2022's Introduction

Original source code

https://pragprog.com/titles/bopytest2/python-testing-with-pytest-second-edition/

Install using PyPI

Create a virtual environment, activate it on POSIX systems, and install pytest

$ python3 -m venv venv_name
$ source venv_name/bin/activate
(venv_name) $ pip install pytest

or using virtualenv

$ python3 -m pip install virtualenv
$ python3 -m virtualenv venv_name
$ source venv_name/bin/activate
(venv_name) $ pip install pytest

Deactivate the venv

(venv_name) $ deactivate

Create a virtual environment, activate it on Windows systems, and install pytest

C:\> python -m venv venv_name
C:\> venv_name\Scripts\activate.bat
(venv_name) C:\> pip install pytest

Activate in PowerShell

C:>venv_name\Scripts\Activate.ps1

Run pytest

Run pytest in the terminal:

$ pytest test_example-01-1--passing.py
===================================================================================================== test session starts ======================================================================================================
 ###
collected 1 item

test_example-01-1--passing.py .                                                                                                                                                                                                      [100%]

====================================================================================================== 1 passed in 0.00s =======================================================================================================
$ pytest -v test_example-01-1--passing.py
===================================================================================================== test session starts ======================================================================================================
###
collected 1 item

test_example-01-1--passing.py::test_passing PASSED                                                                                                                                                                                   [100%]

====================================================================================================== 1 passed in 0.00s =======================================================================================================

Run all tests starting with test_ or ending with _test in the current working directory without traceback

$ pytest --tb=no

Run tests given by their names or (sub)directories in which they are located

$ pytest --tb=no test_example-01-1--passing.py test_example-01-2--failing.py
$ cd ..
$ pytest --tb=no test_examples-01

Run only specified functions

$ cd test_examples-01
$ pytest -v test_example-01-1--passing.py::test_passing

Conventions to keep your test code discoverable by pytest

  • test_<something>.py or <something>_test.py for files
  • test_<something> for methods and functions
  • Test<Something> for classes

Original source code:

https://pragprog.com/titles/bopytest2/source_code

pytest site

https://pytest.org

Demo of Python failure reports with pytest

https://doc.pytest.org/en/latest/example/reportingdemo.html

Assertion rewriting

https://docs.pytest.org/en/latest/how-to/assert.html#assertion-introspection-details

ExceptionInfo

https://docs.pytest.org/en/latest/reference/reference.html#exceptioninfo

The Arrange-Act-Assert or Given-When-Then pattern

https://xp123.com/3a-arrange-act-assert/

https://en.wikipedia.org/wiki/Test-driven_development

https://dannorth.net/introducing-bdd/

Pathlib

https://docs.python.org/3/library/pathlib.html#basic-use

pytest fixtures

https://docs.pytest.org/en/latest/reference/fixtures.html

pytest pytest_generate_tests metafunc

https://docs.pytest.org/en/latest/reference/reference.html#metafunc

pytest-okken-2022's People

Contributors

ax-va avatar

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.