detects if pytest or doctest or pyrunner on pycharm is running
Project description
lib_detect_testenv
Version v1.0.0 as of 2021-11-18 see Changelog
detects test environments: pytest, doctest and pycharm docrunner
automated tests, Travis Matrix, Documentation, Badges, etc. are managed with PizzaCutter (cookiecutter on steroids)
Python version required: 3.6.0 or newer
tested on linux “bionic” with python 3.6, 3.7, 3.8, 3.9, 3.9-dev, pypy3 - architectures: amd64, ppc64le, s390x, arm64
100% code coverage, flake8 style checking ,mypy static type checking ,tested under Linux, macOS, Windows, automatic daily builds and monitoring
Try it Online
You might try it right away in Jupyter Notebook by using the “launch binder” badge, or click here
Usage
detect if test environment is active
def is_testenv_active() -> bool:
"""
returns True if test environment is detected (pytest, doctest, docrunner)
Result
----------
True if Test environment is detected
Exceptions
----------
none
Examples
----------
>>> if not is_setup_test_running(): assert is_testenv_active() == True
"""
detect if doctest is active
def is_doctest_active() -> bool:
"""
returns True if pycharm docrunner is detected
Result
----------
True if docrunner is detected
Exceptions
----------
none
"""
detect if pytest is active
def is_pytest_active() -> bool:
"""
returns True if pytest is detected
Result
----------
True if pytest is detected
Exceptions
----------
none
"""
add a path to the syspath
def add_path_to_syspath(path_to_append: PathLikeOrString) -> None:
"""
adds a path to the syspath
Parameter
----------
path_to_append
the path to append - will be resolved by this function and added to syspath
if path_to_append is a file, its parent directory will be added.
Result
----------
none
Exceptions
----------
none
Examples
----------
>>> add_path_to_syspath(pathlib.Path(__file__).parent)
>>> path1 = str(sys.path)
>>> add_path_to_syspath(pathlib.Path(__file__))
>>> path2 = str(sys.path)
>>> assert path1 == path2
"""
put this in Your __init__.py to automatically add the package directory to the syspath if the test environment is active. This is useful for local testing of packages.
# __init__.py :
# this should be Your first import in __init__
from lib_detect_testenv import *
if is_testenv_active():
add_path_to_syspath(__file__)
Usage from Commandline
Usage: lib_detect_testenv [OPTIONS] COMMAND [ARGS]...
detects if pytest or doctest or pyrunner on pycharm is running
Options:
--version Show the version and exit.
--traceback / --no-traceback return traceback information on cli
-h, --help Show this message and exit.
Commands:
info get program informations
Installation and Upgrade
Before You start, its highly recommended to update pip and setup tools:
python -m pip --upgrade pip
python -m pip --upgrade setuptools
to install the latest release from PyPi via pip (recommended):
python -m pip install --upgrade lib_detect_testenv
to install the latest version from github via pip:
python -m pip install --upgrade git+https://github.com/bitranox/lib_detect_testenv.git
include it into Your requirements.txt:
# Insert following line in Your requirements.txt:
# for the latest Release on pypi:
lib_detect_testenv
# for the latest development version :
lib_detect_testenv @ git+https://github.com/bitranox/lib_detect_testenv.git
# to install and upgrade all modules mentioned in requirements.txt:
python -m pip install --upgrade -r /<path>/requirements.txt
to install the latest development version from source code:
# cd ~
$ git clone https://github.com/bitranox/lib_detect_testenv.git
$ cd lib_detect_testenv
python setup.py install
via makefile: makefiles are a very convenient way to install. Here we can do much more, like installing virtual environments, clean caches and so on.
# from Your shell's homedirectory:
$ git clone https://github.com/bitranox/lib_detect_testenv.git
$ cd lib_detect_testenv
# to run the tests:
$ make test
# to install the package
$ make install
# to clean the package
$ make clean
# uninstall the package
$ make uninstall
Requirements
following modules will be automatically installed :
## Project Requirements
click
cli_exit_tools
Acknowledgements
special thanks to “uncle bob” Robert C. Martin, especially for his books on “clean code” and “clean architecture”
Contribute
I would love for you to fork and send me pull request for this project. - please Contribute
License
This software is licensed under the MIT license
—
Changelog
new MAJOR version for incompatible API changes,
new MINOR version for added functionality in a backwards compatible manner
new PATCH version for backwards compatible bug fixes
v1.0.0
2021-11-19: initial release
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for lib_detect_testenv-1.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 43a9ea3c73f56b99df49193603bda7688a02b974d3849d7db4112cf21b90d66f |
|
MD5 | a49f28b444589a4ca820db0fb0b8a37b |
|
BLAKE2b-256 | 4a0475141eaa09d4f88d98841019f5ca32ac68a7377196138143db9f87072b66 |