-
Notifications
You must be signed in to change notification settings - Fork 141
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Accommodations for running tests in containers that don't match the host OS #1834
Accommodations for running tests in containers that don't match the host OS #1834
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #1834 +/- ##
==========================================
+ Coverage 79.69% 86.15% +6.45%
==========================================
Files 31 33 +2
Lines 4324 4384 +60
Branches 780 465 -315
==========================================
+ Hits 3446 3777 +331
+ Misses 721 428 -293
- Partials 157 179 +22 ☔ View full report in Codecov by Sentry. |
The S3 endpoint URL used in the unit tests was hard-coded to localhost. When executing the tests in a container, a minio sibling container can't be accessed via localhost. This allows setting the endpoint URL via an environment variable, and adds 'BANDERSNATCH_*' to the environment variable passthrough list for Tox. ...noticing that Tox was the reason the environment variable was being ignored took a very long time.
Previously the test_get_hash test used shutil.copy to duplicate a sample file from the project directory into a temp directory for the test. If the project folder is cloned on Windows then bind-mounted into a Linux container, with the test run in the container, the file would have Windows line endings while the test would expect unix line endings based on sys.platform within the container. Instead of copying the file, this change writes the file from a string value using Python's universal newlines support, so the written file will have the same line ending as the platform executing the test. This change trips mypy errors in the pre-commit checks. The errors show when running mypy in the console or via pre-commit, but the MyPy plugin for VS Code *doesn't* and will make the *opposite complaint* if you try to change the file to fix the errors shown in pre-commit. I don't know what to do about that.
Pytest would fail to discover any test files when run in a container with the project folder mounted. Adding these helped, and doesn't change anything when tests are run 'normally' as far as I can tell. I know what each does, but I don't know why the problem was happening in the container specifically, or why these fix it. This is a "web search the error message" -> "find reasonable option on StackOverflow" fix.
2644fee
to
8f03968
Compare
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.
All seems sane. Thanks for making the simple PR and not putting it in with lots of changes to fix our async problems! Really appreciate that.
I have been working on running the tests within a container to better match the CI environment and more easily test with multiple Python versions. I've kept my Docker/Docker Compose configuration in a sibling folder but needed to make a handful of changes to run the tests successfully.
localhost:9000
with something else.sys.platform
doesn't match the platform the project source files were checked out of source control on. My host is Windows, so a sample file had\r\n
endings, but when running the test in a Linux container the test expects\n
.Each of the above is in its own commit with some additional description in the commit log messages.
Since these changes only modify the development environment I'm not sure if they need a corresponding changelog entry.