r/Python • u/wildetea • May 09 '26
Discussion Integration Tests CI
How do people setup integration tests on remote CI?
Consider if you have long integration tests that you don’t want to run on every pull request. How would you trigger integration tests as needed?
I usually separate both by folders as tests/unit and tests/integration, but have also used pytest.mark.integration with flags denoting such config within pyproject.toml.
And i know how to run either of those locally. I am interested on how people trigger this on remote github / bitbucket / gitlab / etc …
Any guidance or references of beat practice would be most appreciated.
1
u/JauriXD May 09 '26
On a previous project I has pytest marked which got set depending on what triggered the GitHub action.
I also had a manual trigger which had some check boxes to select a specific configuration when needed.
BUT please note that the only reason we skipped some of the tests is that wee needed Hardware in the loop which made testing extremely time-consuming (as in multiple hours) and we reduced it down to ~45min default test-time for all PRs.
1
u/MrSlaw May 09 '26
I use conditional actions to run the integration tests (e2e) only after the build step determines whether a release should be created, but before the release itself.
https://i.imgur.com/DhhKZF2.png
pyproject.toml
markers = [
"slow: marks tests as slow (deselect with '-m \"not slow\"')",
"e2e: marks tests requiring external services",
]tests/test_integration.py
import pytest
pytestmark = [pytest.mark.e2e]
async def test_integration_thing():
assert True
@pytest.mark.slow
async def test_slow_integration_thing():
time.sleep(5)
assert True
...1
u/tylerriccio8 May 09 '26
You can use prek or a pre-commit pre-push hook to run integration tests on push, depending on how disruptive to your workflow it would be. I found it kind of annoying after a while.
Others have said on merge hook in github; I’ve found that to be the best.
1
1
u/Rainboltpoe May 09 '26
Can you give one example of an integration test that needs to run for more than a few seconds? I ask because I’ve never encountered a situation where it was necessary. Like maybe the code requires five minutes to pass, so you are literally waiting for five minutes instead of wrapping the system clock and passing it as a dependency.
2
u/PrestigiousStrike779 May 09 '26
For us, we have an event driven system. So the test may submit api calls, then it polls/waits for things to propagate through the system and tries to observe the change that it expects. With queueing and load that could take a bit.
1
u/Rainboltpoe May 09 '26
I would either create a smaller load test that can run in seconds, or run load tests nightly. I would stop making tests wait on queuing. If something is polling the queue then make the polling interval 1ms for the test.
I know you’re not OP. Just explaining what I would do if you were the one asking.
-7
u/KeyPossibility2339 Pythoneer May 09 '26
I use pytests to be run on every PR with 100% coverage and also every merge to main. Defined in github actions yaml file.
1
-10
8
May 09 '26
[removed] — view removed comment
1
u/me_myself_ai May 09 '26
Yup marking them as a “manual” job (in gitlab jargon, at least?) seems to be SOP. I’d also imagine adding them as a dependency for, say, releasing and deploying a new version is popular!
I’ve worked somewhere where massive, 30min+ tests would have to pass for every single commit, and man let me tell you does that get old quick…
1
u/QuasiEvil May 09 '26
I'm just learning this stuff, so what exactly is the distinction between unit tests as evaluated with pytest, and integration tests?