Package: pytest-rts
Coverage-based regression test selection (RTS) plugin for pytestUsageTroubleshootingDevelopmentContributingUsagePlugin is supposed to be used to execute tests related to changes done locally on developer's machine and in CI environment to test pull requests.InitializationTo start using pytest-rts build of coverage DB is needed. ForTrunk Based Developmentmapping database frommasterbranch should be used, forA successful Git branching model-developInstallpytest-covwithpip install pytest-covCreate a.coveragercfile with the following contents inside to configurepytest-cov:[run] 
relative_files = TrueExecutepytest --cov=[path to your package] --cov-context=test --cov-config=.coveragercwhich will run the entire test suite and build a mapping database in.coveragefileRename the coverage file.coverageproduced bypytest-covto your liking. Example:mv .coverage pytest-rts-coverageNote that--cov-config=.coveragercis optional parameter here. For more info seeofficial docs.Local usageTests from changes in Git working directoryInstallpytest-rtswithpip install pytest-rtsCreate a branchgit checkout -b feat/new-featureMake changes in your codeRun the tool withpytest --rts --rts-coverage-db=[path to database]As a result only tests related to changes in working directory will be executed.Tests from changes in Git working directory + committed changesInstallpytest-rtswithpip install pytest-rtsCreate a branchgit checkout -b feat/new-featureMake changes in your code and commit themRun the tool withpytest --rts --rts-coverage-db=[path to database] --rts-from-commit=[database initialization commithash]The current git working directory copy will be compared to the given commithash. Tests for changes in commits and in the working directory will be executed.Usage in CIIn the main branch (masterordevelop) make sure you run entire test suite andcommit back coverage databaseor, if the database size is big, upload it to some storageIn pull requests:make sure you have coverage database from the main branch located next to the coderunpytest --rts --rts-coverage-db=[path to database] --rts-from-commit=[database initialization commithash]One of the ways to organize it in Makefile would be:BRANCH_NAME=$(shellgitbranch|sed-n-e's/^\* \(.*\)/\1/p')ifeq ($(BRANCH_NAME), master)test:test-masterelsetest:test-prendiftest-master:pytest\--exitfirst\--cov\--cov-context=test\--cov-config=.coveragercmv.coveragemapping.dbgitaddmapping.dbgitcommit-m"test: updated RTS mapping DB"gitpushtest-pr:MASTER_COMMIT=$(shellgitmerge-baseremotes/origin/masterHEAD)test-pr:gitcheckout$(MASTER_COMMIT)mapping.dbpytest\--exitfirst\--rts\--rts-coverage-db=mapping.db\--rts-from-commit=$(MASTER_COMMIT)&&[$$?-eq0]||[$$?-eq5]Exit code tests/overwrite&& [ $$? -eq 0 ] || [ $$? -eq 5 ]is needed in cases when no tests are found for execution.
See Troubleshooting section for more information.Usage with coverage thresholdYou might desire to usepytest-covwith the--cov-fail-under=MINflag. When usingpytest-rtsthis is somewhat possible but the reported coverage percentage will not represent actual coverage. If you wish to combine the usage of--rtsand the coverage threshold, do the following:Initialize the coverage database as usualLeave the.coveragefile untouched or rename it to start with.coverage.. For example.coverage.rts.dbDo your changes and add--cov=[path to code]and--cov-appendto the flags. For examplepytest --rts --rts-coverage-db=.coverage --cov=. --cov-appendpytest-covwill automatically combine the coverage file for the previous full run and the current RTS run. Bear in mind that the coverage file will now have added data. Create a backup of your full test run coverage file if you wish to keep it intact.Troubleshootingpytest --rtsreturns non-zero code:command returns one of thepytest exit codes. For example if pytest-rts
module found no tests to execute resulting code will be 5 "No tests were collected"DevelopmentSeeDEVELOPER.mdfor more infoContributingContributing GuidelinesRead through ourcontributing guidelinesto learn about our submission process, coding rules and more.Code of ConductHelp us keep the project open and inclusive. Please read and follow ourCode of Conduct.AcknowledgementThe package was developed byF-Secure CorporationandUniversity of Helsinkiin scope ofIVVES project. This work was labelled byITEA3and funded by local authorities under grant agreement “ITEA-2019-18022-IVVES”