Giter Club home page Giter Club logo

pytest-primer's Introduction

Sample commands to experiment with the code in this repository:


The files involved in the following commands are:

  • pytest-primer/lib/num_gen.py
  • pytest-primer/tests/conftest.py
  • pytest-primer/tests/test_num_gen.py

Omits console output generated by the test

[/tests]$ pytest test_num_gen.py

The -s option prints messages generated by the test

[/tests]$ pytest -s test_num_gen.py

Runs all tests within a test class

[/tests]$ pytest -s test_num_gen.py::TestNumGen 

Runs a specific method within a test class

[/tests]$ pytest -s test_num_gen.py::TestNumGen::test_gen_odds
[/tests]$ pytest -s test_num_gen.py::TestNumGen::test_gen_evens
[/tests]$ pytest -s test_num_gen.py::TestNumGen::test_gen_squares

Runs only tests specified with markers

[/tests]$ pytest -s test_num_gen.py -m odds
[/tests]$ pytest -s test_num_gen.py -m evens
[/tests]$ pytest -s test_num_gen.py -m squares

The files involved in the following commands are:

  • pytest-primer/conftest.py
  • pytest-primer/tests/conftest.py
  • pytest-primer/tests/test_cmd_opt.py

Runs a test that uses the default command option value as a test input

[/tests]$ pytest -s test_cmd_opt.py

Runs a test that uses a string input to a command loption as a test input

[/tests]$ pytest -s test_cmd_opt.py --cmdopt='dog'
[/tests]$ pytest -s test_cmd_opt.py --cmdopt='cat'

The files involved in the following command are:

  • pytest-primer/lib/pizza.py
  • pytest-primer/conftest.py
  • pytest-primer/tests/conftest.py
  • pytest-primer/tests/test_testdata.py

Runs a test that uses test input data in json format

[/tests]$ pytest test_testdata.py -s --testdata="{'size':'large', 'crust':'thin', 'toppings':['sausage', 'peppers', 'onions']}"

Finally, here are the related links to topics covered from the official py.test documentation:

  1. Directory layout best practices https://docs.pytest.org/en/latest/goodpractices.html

  2. File organization and fixtures https://docs.pytest.org/en/latest/fixture.html

  3. markers and test execution https://docs.pytest.org/en/latest/example/markers.html https://docs.pytest.org/en/latest/usage.html

  4. Passing command line options https://docs.pytest.org/en/latest/example/simple.html

  5. Parametizing tests using cli options https://docs.pytest.org/en/latest/example/parametrize.html https://docs.pytest.org/en/latest/parametrize.html

pytest-primer's People

Contributors

btjd 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.