Python Testing Example: pytest
This project has two modules:
com.automationpanda.example.calc_funccontains math functions.
com.automationpanda.example.calc_classcontains a basic Calculator class.
Test modules are placed under the
tests is not a Python package and has no "__init__.py" file.
pytest has many command line options with a powerful discovery mechanism:
python -m pytestto discover and run all tests from the current directory
python -m pytest -vto explicitly print the result of each test as it is run
python -m pytest tests/test_calc_func.pyto run only the math function tests
python -m pytest tests/test_calc_class.pyto run only the Calculator class tests
python -m pytest --junitxml=results.xmlto generate a JUnit-style XML test report
python -m pytest -hfor command line help
It is also possible to run pytest directly with the "pytest" or "py.test" command, instead of using the longer "python -m pytest" module form. However, the shorter command does not append the current directory path to PYTHONPATH.
Configuration settings may also be added to "pytest.ini".