question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Testing errors when streaming

See original GitHub issue

I currently have a problem with errors when I try to test a streaming endpoint, namely when I use the stream_with_context flask function/decorator to keep the context around, as I am streaming from a database which client is on current_app.

Essentially, the test passes, but then pytest-flask errors with a message about it having popped the wrong request context: AssertionError: Popped wrong request context. (<RequestContext 'http://localhost/stream' [GET] of app> instead of <RequestContext 'http://localhost/' [GET] of app>)

Or at least I think it’s pytest-flask.

I have a small gist that demonstrates the issue: https://gist.github.com/cknv/152d81ffcc4a74be491d, though it might be a little on the primitive side, but for me it does demonstrate the error. If you need some more information, I would of course be more than happy to provide it 😃

For completeness sake, I am running python 3.5.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:7
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
pbabbicolacommented, Mar 1, 2019

Is this “fix” still working? I am running into the same problem here and creating a fixture and explicitly pushing the context is not working for me.

1reaction
davidismcommented, Jul 1, 2022

A fix was previously merged in to Flask, but I’m now reverting that. The behavior described here is correct. The context for stream_with_context is preserved separately from with client, and should remain as long as the generator is still running. Your test either needs to read response.data, or call response.close(). Either of those will close the generator and release the context. (This might not have been the case at the time it was reported, I’ve made other changes to how the test client handles the response since then.)

This issue should be closed, it’s not an issue with Pytest-Flask or Flask.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Testing your Video Player with Bad Streams
Finding bad streams to test your player error handling is hard. It takes time to find or generate the streams you need.The Eyevinn...
Read more >
6 steps to solving your streaming video problems - TechHive
Before you start running connection tests, try streaming from a different video source to see if the issues persist.
Read more >
Troubleshooting Device.Streaming Testing | Microsoft Learn
To troubleshoot issues that occur with Device.Streaming tests, follow these steps: Review the following Windows Hardware Lab Kit (Windows HLK) ...
Read more >
Test should pass on stream error, fail on success
I'm trying to write a mocha test which passes on a stream error but fails if the stream ends without an error. Detecting...
Read more >
Error and Stream Handling | Android Open Source Project
Transient errors in image capture must be reported through ICameraDeviceCallbacks::notify() with the appropriate error code.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found