Package: pytest-pokie
pytest-pokiePytest plugin to run tests on pokie applicationsThe pytest-pokie plugin extracts the pokie-based Flask application from the global namespace, and exposes a set
of predefined fixtures for pokie structures.Note: Currently, only PostgreSQL is supported; the configured database user must have database creation/drop privileges;
The plugin also assumes the user can connect to the database 'postgres', as it is used as the default db for
administrative
operations.configuration parametersParameterDescriptionTEST_DB_NAMEPostgreSQL test database nameTEST_DB_HOSTPostgreSQL hostTEST_DB_PORTPostgreSQL portTEST_DB_USERPostgreSQL userTEST_DB_PASSWORDPostgreSQL passwordTEST_DB_SSLif True, enforces SSLTEST_MANAGE_DBif False, no db is managed via pytest-pokieTEST_SHARE_CTXif False, create a new application instance between tests (default)TEST_DB_REUSEif False, drops and recreates the database between tests (default)TEST_SKIP_MIGRATIONSif False, runs migrations when creating the databaseTEST_SKIP_FIXTURESif False, runs fixtures when creating the databaseapplication lifecycleTEST_SHARE_CTXFalse (default): Each test is run with a separate application instance; the application is bootstrapped at each
test, by using
the existing application factory.True: All tests are run with the same pokie FlaskApplication and Flask instance; services, events, etc. will be
managed
and cached as in a production run.database management optionsPlease note: The credentials provided to the test databasemusthave enough privileges for the required operations,
such as creating and dropping databases.TEST_MANAGE_DBFalse (default): If TEST_MANAGE_DB is False, database management is completely ignored, and available db connection
is the regular
application connection. All database test configurations are ignored. With this mode, it is up to the developer to
ensure a clean state between database runs.True: If TEST_MANAGE_DB is True, pytest-pokie will manage the database connection using the available test
credentials.
The global database connection is replaced with the test connection, and fixtures and migrations may be executed between
tests.TEST_DB_REUSEFalse (default): if TEST_DB_REUSE is False, pytest-pokie will attempt to drop and recreate the test database between
each test.True: if TEST_DB_REUSE is True, pytest-pokie will not drop the testing database if exists. If it doesn't exist, it
will attempt to create the database and optionally run migrations and fixtures, depending on TEST_SKIP_MIGRATIONS and
TEST_SKIP_FIXTURES values.TEST_SKIP_MIGRATIONSFalse (default): Existing SQL migrations will be run when the database is recreated.True: Existing SQL migrations are ingored, even if the database is recreated.TEST_SKIP_FIXTURESFalse (default):Existing fixtures will be run when the database is recreated.True: Existing fixtures are ingored, even if the database is recreated.avaliable fixturesNote: fixtures depend on the predefined values for the different DI constants as specified on thepokie.constantsfile.FixtureDescriptionpokie_appPokie Flask objectpokie_configPokie Config objectpokie_diPokie Di objectpokie_dbPokie Database clientpokie_clientFlask test clientwriting tests for pokie applicationsPytest must be invoked using the internal pokie pytest runner. The pytest runner will automatically add the pytest-pokie
plugin to pytest. All additional pytest command-line arguments can be specified:$pythonmain.pypytest--help[Pokie]Runningpytestwith:['--help']usage:main.py[options][file_or_dir][file_or_dir][...]positionalarguments:file_or_dir

general:-kEXPRESSIONonlyruntestswhichmatchthegivensubstringexpression.Anexpressionisapythonevaluatableexpressionwhereallnamesaresubstring-matchedagainsttestnamesandtheirparentclasses.Example:-k'test_method or test_other'matchesalltestfunctionsandclasseswhosenamecontains'test_method'or'test_other',while-k'not test_method'matchesthosethatdon't contain 'test_method' in their names. -k'nottest_methodandnottest_other' will eliminate the matches. Additionally keywords are matched to classes and functions containing extra names in their 'extra_keyword_matches' set, as well as functions whichhave names assigned directly to them. The matching is case-insensitive.-m MARKEXPR           only run tests matching given mark expression.For example: -m 'mark1andnotmark2'.--markersshowmarkers(builtin,pluginandper-projectones).-x,--exitfirstexitinstantlyonfirsterrororfailedtest.--fixtures,--funcargs(...)$The scaffold structure is similar to the common pytest usage:some_module/(...)main.py
tests/__init__.pysome_module/__init__.pytest_something.pytest_something.py:deftest_example_1(pokie_app,pokie_di):assertpokie_appisnotNoneassertpokie_app.di==pokie_dideftest_example_2(pokie_db,pokie_service_manager):assertpokie_dbisnotNoneassertpokie_service_managerisnotNoneAnd to run the tests:$python3main.pypytestusing toxExample tox.ini:[base]name=module_name[tox]envlist=py39py310[testenv]deps=-rrequirements-dev.txtcommands=python3 main.py pytestExample requirements-dev.txt:pytest==7.3.1
pytest-cov==4.0.0
pytest-testdox==3.0.1pokie==0.4.0
pytest-pokie==0.2.0flake8==6.0.0flake8_black==0.3.6coverage==7.2.5tox==4.5.1
setuptools~=60.0.0Running with tox:$tox-epy310