Skip to content
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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

tylerhutcherson
Copy link
Collaborator

@tylerhutcherson tylerhutcherson commented Feb 5, 2025

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.

@tylerhutcherson
Copy link
Collaborator Author

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
Copy link
Collaborator

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).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

scripts.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@abrookins abrookins left a 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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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
Copy link
Collaborator

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.

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants