
Product
Introducing Reports: An Extensible Reporting Framework for Socket Data
Explore exportable charts for vulnerabilities, dependencies, and usage with Reports, Socket’s new extensible reporting framework.
pytest-rts
Advanced tools
Plugin 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.
To start using pytest-rts build of coverage DB is needed. For Trunk Based Development mapping database from master branch should be used, for A successful Git branching model - develop
pip install pytest-cov.coveragerc file with the following contents inside to configure pytest-cov:[run]
relative_files = True
pytest --cov=[path to your package] --cov-context=test --cov-config=.coveragerc which will run the entire test suite and build a mapping database in .coverage file.coverage produced by pytest-cov to your liking. Example: mv .coverage pytest-rts-coverageNote that --cov-config=.coveragerc is optional parameter here. For more info see official docs.
pytest-rts with pip install pytest-rtsgit checkout -b feat/new-featurepytest --rts --rts-coverage-db=[path to database]As a result only tests related to changes in working directory will be executed.
pytest-rts with pip install pytest-rtsgit checkout -b feat/new-featurepytest --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.
master or develop) make sure you run entire test suite and
pytest --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 = $(shell git branch | sed -n -e 's/^\* \(.*\)/\1/p')
ifeq ($(BRANCH_NAME), master)
test: test-master
else
test: test-pr
endif
test-master:
pytest \
--exitfirst \
--cov \
--cov-context=test \
--cov-config=.coveragerc
mv .coverage mapping.db
git add mapping.db
git commit -m "test: updated RTS mapping DB"
git push
test-pr: MASTER_COMMIT = $(shell git merge-base remotes/origin/master HEAD)
test-pr:
git checkout $(MASTER_COMMIT) mapping.db
pytest \
--exitfirst \
--rts \
--rts-coverage-db=mapping.db \
--rts-from-commit=$(MASTER_COMMIT) && [ $$? -eq 0 ] || [ $$? -eq 5 ]
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.
You might desire to use pytest-cov with the --cov-fail-under=MIN flag. When using pytest-rts this is somewhat possible but the reported coverage percentage will not represent actual coverage. If you wish to combine the usage of --rts and the coverage threshold, do the following:
.coverage file untouched or rename it to start with .coverage.. For example .coverage.rts.db--cov=[path to code] and --cov-append to the flags. For example pytest --rts --rts-coverage-db=.coverage --cov=. --cov-appendpytest-cov will 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.pytest --rts returns non-zero code: command returns one of the
pytest exit codes. For example if pytest-rts
module found no tests to execute resulting code will be 5 "No tests were collected"See DEVELOPER.md for more info
Read through our contributing guidelines to learn about our submission process, coding rules and more.
Help us keep the project open and inclusive. Please read and follow our Code of Conduct.
The package was developed by F-Secure Corporation and University of Helsinki in scope of IVVES project. This work was labelled by ITEA3 and funded by local authorities under grant agreement “ITEA-2019-18022-IVVES”
FAQs
Coverage-based regression test selection (RTS) plugin for pytest
We found that pytest-rts demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Explore exportable charts for vulnerabilities, dependencies, and usage with Reports, Socket’s new extensible reporting framework.

Product
Socket for Jira lets teams turn alerts into Jira tickets with manual creation, automated ticketing rules, and two-way sync.

Company News
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.