Title: Theory / Important / CS / Programming / Python / PyTest
Tags: computer_to_instruction fromCommandLine hasNotNewEffectReturnsMeaning FromInstruction FromVariables automatedNewLineAfterCommaSpace examplesSwitchExample1 hasSeenConjDef

Name: pytest
Definition: python frameworks which make it easy to write small tests, yet scales to support complex functional testing for applications and libraries.
Page: https://docs.pytest.org/en/latest/

Instruction: pytest
Page: https://docs.pytest.org/en/latest/
Effect: start pytest
Language: Python

Variable: test_* or *_test
Meaning: File automatically tested by pytest
Page: https://docs.pytest.org/en/latest/
Language: Python
Index: file

Instruction: assert foo
Page: https://docs.pytest.org/en/latest/
Effect: State that if foo does not hold, there is a failure in pytest over this line
Language: Python
Context: pytest

Instruction: pytest.raises(foo) as plop:
bar
Page: https://docs.pytest.org/en/latest/assert.html#assert
Effect: Assert that bar raise exception foo.
Set plop to the actual exception
Language: Python
Context: pytest

Instruction: pytest.raises(foo):
  bar
Page: https://docs.pytest.org/en/latest/assert.html#assert
Effect: Assert that bar raise exception foo
Language: Python
Context: pytest

Page: https://docs.pytest.org/en/latest/
Effect: restrict the test to be run on file foo and not on all default files
Language: Python
Context: pytest
Abbreviation: -q foo

Fla: --fixtures
Effect: shows builtin and custom fixtures
Page: https://docs.pytest.org/en/latest/
Prefix: pytest

Fla: --fixtures -v
Effect: shows builtin and custom fixture, even the one starting by _
Page: https://docs.pytest.org/en/latest/
Prefix: pytest

Instruction: tmpdir
Page: https://docs.pytest.org/en/latest/
Effect: a py.path.local object which offers os.path methods and more. provide a temporary directory unique to the test invocation, created in the base temporary directory.
Language: Python
Context: pytest

Fla: --basetemp foo
Effect: set foo as the base directory for temporary directories
Page: https://docs.pytest.org/en/latest/
Prefix: pytest

Instruction: python -m pytest foo
Page: https://docs.pytest.org/en/latest/
Effect: similar to pytest foo, adding current directory to sys.path
Language: Python

Fla: --version
Effect: shows where pytest was imported from
Page: https://docs.pytest.org/en/latest/usage.html#cmdline
Prefix: pytest

Fla: --help
Effect: show help on command line and config file options
Page: https://docs.pytest.org/en/latest/usage.html#cmdline
Prefix: pytest
Flag abbreviation: -h

Fla: -x
Effect: stop after first failure
Page: https://docs.pytest.org/en/latest/usage.html#cmdline
Prefix: pytest

Fla: --maxfail=foo
Effect: stop after foo failures
Page: https://docs.pytest.org/en/latest/usage.html#cmdline
Prefix: pytest

Instruction: directory
Page: https://docs.pytest.org/en/latest/usage.html#cmdline
Effect: run test from directory only
Language: Python
Context: pytest

Instruction: -k "foo"
Page: https://docs.pytest.org/en/latest/usage.html#cmdline
Effect: run tests which contain names that match foo
Language: Python
Context: pytest
Extra: It can include Python operators that use filenames, class names and function names as variables.
Example: -k "MyClass and not method" run TestMyClass.test_something but not TestMyClass.test_method_simple.

Name: the node id of t
Definition: the file name
Page: https://docs.pytest.org/en/latest/usage.html#cmdline
Variables: t a test in a python file
Context: pytest
Definition2: the class, function name, parameters from parametrization
Example: test_mod.py::TestClass::test_method
Conjdef: In this order, separatted by ::

Instruction: node id
Page: https://docs.pytest.org/en/latest/usage.html#cmdline
Effect: test only the test designed by node id
Language: Python
Context: pytest

Fla: --pyargs pkg.testing
Effect: import pkg.testing and use its filesystem location to find and run tests from.
Page: https://docs.pytest.org/en/latest/usage.html#cmdline
Prefix: pytest

Fla: --tb=foo
Effect: Change traceback format to foo
Page: https://docs.pytest.org/en/latest/usage.html#cmdline
Prefix: pytest

Fla: --tb=auto
Effect: (default) 'long' tracebacks for the first and last entry, but 'short' style for the other entries
Page: https://docs.pytest.org/en/latest/usage.html#cmdline
Prefix: pytest

Fla: --tb=long
Effect: exhaustive, informative traceback formatting
Page: https://docs.pytest.org/en/latest/usage.html#cmdline
Prefix: pytest

Fla: --tb=short
Effect: shorter traceback format
Page: https://docs.pytest.org/en/latest/usage.html#cmdline
Prefix: pytest

Fla: --tb=line
Effect: only one line per failure
Page: https://docs.pytest.org/en/latest/usage.html#cmdline
Prefix: pytest

Fla: --tb=native
Effect: Using a formatting similar to Python standard library.
Page: https://docs.pytest.org/en/latest/usage.html#cmdline
Prefix: pytest

Fla: --tb=no
Effect: no traceback at all
Page: https://docs.pytest.org/en/latest/usage.html#cmdline
Prefix: pytest

Fla: --full-trace
Effect: causes very long traces to be printed on error (longer than --tb=long). It also ensures that a stack trace is printed on KeyboardInterrupt (Ctrl+C). This is very useful if the tests are taking too long and you interrupt them with Ctrl+C to find out where the tests are hanging. By default no output will be shown (because KeyboardInterrupt is caught by pytest). By using this option you make sure a trace is shown.
Page: https://docs.pytest.org/en/latest/usage.html#cmdline
Prefix: pytest

Fla: --showlocals
Effect: show local variables in tracebacks
Page: https://docs.pytest.org/en/latest/usage.html#cmdline
Prefix: pytest
Flag abbreviation: -l

Fla: --pdb
Effect: invoke the Python debugger on every failure.
Page: https://docs.pytest.org/en/latest/usage.html#cmdline
Prefix: pytest

Instruction: sys.last_value sys.last_type and sys.last_traceback.
Page: https://docs.pytest.org/en/latest/usage.html#cmdline
Effect: the exception information
Language: Python
Context: pytest
Where to use it: python debug, from a failure

Instruction: pdb.set_trace()
Page: https://docs.pytest.org/en/latest/usage.html#cmdline
Effect: set a breakpoint in your code.
pytest automatically disables its output capture for that test:
Language: Python

Fla: --durations=foo
Effect: get a list of the slowest foo test durations
Page: https://docs.pytest.org/en/latest/usage.html#cmdline
Prefix: Python

Fla: --junitxml=foo
Effect: create a XML file foo which can be read by Jenkins or other Continuous integration servers
Page: https://docs.pytest.org/en/latest/usage.html#cmdline
Prefix: Python

Variable: pytest
Meaning: pytest configuration file
Page: https://docs.pytest.org/en/latest/usage.html#cmdline
Language: Python
Typ: file

Instruction: record_property(foo, bar)
Page: https://docs.pytest.org/en/latest/usage.html#cmdline
Effect: Add <property name="foo" value="bar" /> to the xml output
Language: Python
Context: pytest
Library: record_property as argument of the tested function
Kind: file

Instruction: test_* function/method
Page: https://docs.pytest.org/en/latest/usage.html#cmdline
Effect: The function/method to test
Language: Python
Context: pytest
Where to use it: outside of class, or inside Tested classes without __init__ method

Instruction: Test* class
Page: https://docs.pytest.org/en/latest/usage.html#cmdline
Effect: The class to test
Language: Python
Context: pytest

Instruction: assert foo, "bar"
Page: https://docs.pytest.org/en/latest/assert.html#assert
Effect: print bar if assertion foo fails
Language: Python
Context: pytest

Question: Which pytest test to use for exception deliberately raised in our own code
Answer: pytest.raise
Page: https://docs.pytest.org/en/latest/assert.html#assert
Context: pytest

Question: Which pytest test to use for exception sent by unfixed bug
Answer: @pytest.mark.xfail
Page: https://docs.pytest.org/en/latest/assert.html#assert
Context: pytest

Question: what happen when asserting equality of set/list
Answer: it shows an element from each container not occuring in the other one, if such element exists
Page: https://docs.pytest.org/en/latest/assert.html#assert
Context: pytest

Instruction: pytest_assertrepr_compare(
  foo,bar,
  plop
)
Page: https://docs.pytest.org/en/latest/assert.html#assert
Effect: Assuming "bar foo plop" does not hold
Language: Python
Context: pytest
Returns: the message to show for this failure
Where to use it: conftest.py

Instruction: PYTEST_DONT_REWRITE in docstring of module
Page: https://docs.pytest.org/en/latest/assert.html#assert
Effect: Disable rewriting for this module
Language: Python
Context: pytest

Fla: --assert=plain
Effect: Disable rewriting for all modules
Page: https://docs.pytest.org/en/latest/assert.html#assertt
Prefix: pytest