[feature] Add st.file_uploader support to AppTest#14341
Conversation
Add FileUploader widget class to AppTest framework enabling file upload testing in Streamlit applications. Files are registered with the MemoryUploadedFileManager before script runs using pre-generated UUIDs. Closes #8093 Co-Authored-By: Claude Opus 4.6 <[email protected]>
✅ PR preview is ready!
|
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
There was a problem hiding this comment.
Pull request overview
Adds st.file_uploader support to the st.testing.v1.AppTest framework, enabling tests to programmatically upload/clear files and have apps under test consume them via Streamlit’s uploaded-file machinery.
Changes:
- Introduces a
FileUploaderwidget node in the testing element tree withset_value(),upload(), andclear()APIs. - Registers uploaded file bytes into the runner’s
MemoryUploadedFileManagerprior to each script run. - Adds unit tests for single/multiple uploads, incremental uploads, clearing, and key-based access.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| lib/tests/streamlit/testing/element_tree_test.py | Adds coverage for AppTest.file_uploader interactions and basic behavior. |
| lib/streamlit/testing/v1/element_tree.py | Adds FileUploader widget representation and parsing/accessors in the element tree. |
| lib/streamlit/testing/v1/app_test.py | Adds pre-run file registration so uploaded files are available during script execution. |
📈 Python coverage change detectedThe Python unit test coverage has increased by 0.0439%
✅ Coverage change is within normal range. Coverage by files
|
st.file_uploader support to AppTest
Address review comments about FileUploader widget state persistence: - Use InitialValue sentinel pattern to distinguish "not set" from "cleared" - Fall back to existing UploadedFile objects in session_state when no explicit set_value/upload/clear was called, similar to other widgets - Add register_file() helper method to LocalScriptRunner to avoid accessing private attributes from AppTest - Add tests for file persistence across multiple run() calls Co-Authored-By: Claude Opus 4.6 <[email protected]>
SummaryThis PR adds Code QualityThe implementation is well-structured and follows existing codebase patterns (e.g., Strengths (consensus):
Issues identified:
Test CoverageAll reviewers agreed the test coverage is strong. Tests cover:
Gaps identified:
These are enhancement suggestions, not blocking gaps. Backwards CompatibilityConsensus: No breaking changes. The change is purely additive — new Security & RiskConsensus: No security concerns. All changes are confined to the AppTest testing framework, using External test recommendation
AccessibilityNot applicable. No frontend changes in this PR. Recommendations
Reviewer Agreement Summary
VerdictAPPROVED: The implementation is well-designed, thoroughly tested, and follows existing codebase patterns. Two of three reviewers approved. The This is a consolidated AI review by 📋 Review by `gemini-3.1-pro`SummaryThis PR adds support for Code QualityThe code is well-structured and follows the existing patterns for Test CoverageThe PR includes comprehensive unit tests in Backwards CompatibilityThese changes are purely additive to the Security & RiskThere are no security concerns or regression risks identified. The changes are confined to the testing framework and use the existing External test recommendationRecommendation: No AccessibilityN/A - This PR does not contain frontend changes. RecommendationsNone. The implementation is solid and well-tested. VerdictAPPROVED: The implementation of This is an automated AI review by 📋 Review by `gpt-5.3-codex-high`SummaryThis PR adds Code QualityOverall structure is clean and follows existing AppTest patterns, but there is one blocking behavior issue:
Test CoverageCoverage is strong for core paths (single upload, multi upload via
Backwards CompatibilityNo breaking changes to production Security & RiskNo direct security-sensitive runtime paths were modified (no server endpoint/auth/cookie/CORS/session transport changes in production code). Main risk is functional mismatch in test simulation for additive uploads, which can lead to false confidence in app tests. External test recommendation
AccessibilityNo frontend/UI code changes were made ( Recommendations
VerdictCHANGES REQUESTED: The new AppTest file uploader support is close, but This is an automated AI review by 📋 Review by `opus-4.6-thinking`SummaryThis PR adds
Code QualityThe implementation is well-structured and closely follows existing patterns in the codebase (e.g., Strengths:
Issues:
Test CoverageThe tests are comprehensive and well-structured:
Gaps:
Backwards CompatibilityThis change is purely additive with no breaking changes:
Previously, Security & RiskNo security concerns. All changes are confined to the
Regression risk is low. The change is additive and does not modify existing widget handling or script running logic. External test recommendation
AccessibilityNot applicable. There are no frontend changes in this PR. The Recommendations
VerdictAPPROVED: Well-implemented, additive feature that follows existing codebase patterns with comprehensive tests. The dead code in the test and the This is an automated AI review by |
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
Describe your changes
Adds
st.file_uploadersupport to the AppTest testing framework, addressing a long-standing feature request.FileUploaderwidget class toelement_tree.pywithset_value(),upload(), andclear()methodsapp_test.pythat registers uploaded files withMemoryUploadedFileManagerbefore script runsExample usage:
GitHub Issue Link (if applicable)
Testing Plan
upload()methodclear()methodAgent metrics