-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Improve CI test runtime with pytest-xdist #270
base: main
Are you sure you want to change the base?
Conversation
Some issue with the latest redis stack version??? |
scripts.py
Outdated
|
||
|
||
def test_verbose(): | ||
subprocess.run( | ||
["python", "-m", "pytest", "-vv", "-s", "--log-level=CRITICAL"], check=True | ||
["python", "-m", "pytest", "-n", "6", "-vv", "-s", "--log-level=CRITICAL"], check=True |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd use "auto" here. As a data point, if I use "auto" and set Docker's resources to use all cores, pytest assigns 14 cores and I see a ~16s speedup locally (76.39s with 6 cores, 61.40s with "auto"/14 cores).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work! That's a big savings in local testing time that should also save time and money in CI over the long run.
compose.start() | ||
|
||
# If you mapped the container port 6379:6379 in docker-compose.yml, | ||
# you might have collisions across workers. If you rely on ephemeral | ||
# host ports, remove the `ports:` block in docker-compose.yml and do: | ||
redis_host, redis_port = compose.get_service_host_and_port("redis", 6379) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
redis_host, redis_port = compose.get_service_host_and_port("redis", 6379) | |
#redis_host, redis_port = compose.get_service_host_and_port("redis", 6379) |
redis_host, redis_port = compose.get_service_host_and_port("redis", 6379) | ||
redis_url = f"redis://{redis_host}:{redis_port}" | ||
os.environ["REDIS_URL"] = redis_url |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should line 35 also be commented out? (I added a suggestion for it.)
This isn't a blocker for me, but ideally, the codebase should only support and suggest behavior that's configurable at runtime through environment variables or CLI flags, without requiring developers to comment or uncomment code.
pytest-xdist
runs workers to tackle the test suite concurrently (using more cpus):https://pytest-xdist.readthedocs.io/en/stable/distribution.html#running-tests-across-multiple-cpus
The addition of this tool AND some small updates to testcontainer usage (for Redis instances) helps us achieve a ~3-4x speed up locally.