Skip to content

Commit f2cd489

Browse files
docs: added example of Makefile
1 parent 3807a30 commit f2cd489

File tree

1 file changed

+38
-3
lines changed

1 file changed

+38
-3
lines changed

README.md

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
<img src="https://github.com/F-Secure/pytest-rts/raw/master/docs/imgs/pytest-rts-logo.png" width="120px" height="120px"/>
2-
3-
# Coverage-based regression test selection (RTS) plugin for pytest
1+
<table border="0"><tr>
2+
<td width="120px">
3+
<img src="https://github.com/F-Secure/pytest-rts/raw/master/docs/imgs/pytest-rts-logo.png"/>
4+
</td>
5+
<td><h1 style="padding: 0; margin: 0;">Coverage-based regression test selection (RTS) plugin for pytest</h1></td>
6+
</tr></table>
47

58
- [Usage](#usage)
69
- [Troubleshooting](#troubleshooting)
@@ -24,6 +27,8 @@ relative_files = True
2427
3. Execute `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
2528
4. Rename the coverage file `.coverage` produced by `pytest-cov` to your liking. Example: `mv .coverage pytest-rts-coverage`
2629

30+
Note that `--cov-config=.coveragerc` is optional parameter here. For more info see [official docs](https://pytest-cov.readthedocs.io/en/latest/config.html#caveats).
31+
2732
### Local usage
2833

2934
1. Install `pytest-rts` with `pip install pytest-rts`
@@ -41,6 +46,36 @@ As a result only tests related to changes in working directory and branch will b
4146
* In pull requests:
4247
* make sure you have coverage database from the main branch located next to the code
4348
* run `pytest --rts --rts-coverage-db=[path to database]`
49+
50+
One of the ways to organize it in Makefile would be:
51+
52+
```make
53+
test:
54+
@[ "$(BRANCH_NAME)" = "master" ] && $(MAKE) test-master || $(MAKE) test-pr
55+
56+
test-master:
57+
pytest \
58+
--exitfirst \
59+
--cov \
60+
--cov-context=test \
61+
--cov-config=.coveragerc
62+
mv .coverage mapping.db
63+
git add mapping.db
64+
git commit -m "test: updated RTS mapping DB"
65+
git push
66+
67+
test-pr: MASTER_COMMIT=$(shell git merge-base remotes/origin/master HEAD)
68+
test-pr:
69+
git checkout $(MASTER_COMMIT) mapping.db
70+
pytest \
71+
--exitfirst \
72+
--rts \
73+
--rts-coverage-db=mapping.db \
74+
--rts-from-commit=$(MASTER_COMMIT) && [ $$? -eq 0 ] || [ $$? -eq 5 ]
75+
```
76+
77+
Exit code tests/overwrite `&& [ $$? -eq 0 ] || [ $$? -eq 5 ]` is needed in cases when no tests are found for execution.
78+
See Troubleshooting section for more information.
4479

4580
## <a name="troubleshooting"></a> Troubleshooting
4681

0 commit comments

Comments
 (0)