[Core] Update pytest fixture scope#45563
Merged
pvaneck merged 1 commit intoAzure:mainfrom Mar 9, 2026
Merged
Conversation
Module level scoping caused the flask server to be started and stopped multiple times, causing flakiness. Make it session-scoped to only start it once. Signed-off-by: Paul Van Eck <paulvaneck@microsoft.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR reduces test flakiness in azure-core-experimental by ensuring the Flask-based core test server is started once per test run (instead of repeatedly per module), and by invoking Flask via the active Python interpreter.
Changes:
- Switches the
portpytest fixture frommodulescope tosessionscope to avoid repeated server start/stop cycles. - Updates test server startup command to use
sys.executable -m flask ...instead of relying onflaskbeing onPATH.
Comments suppressed due to low confidence (1)
sdk/core/azure-core-experimental/tests/conftest.py:69
cmdis built as a single string and passed tosubprocess.Popen. On Windows withshell=False, this can fail whensys.executablecontains spaces (e.g., a Python installed underProgram Files) because the executable path won’t be parsed/quoted correctly. Consider passing args as a list (e.g.,[sys.executable, "-m", "flask", "run", "-p", str(port)]) and usingshell=Falseon all platforms (you can keeppreexec_fn=os.setsidfor non-Windows) to avoid quoting issues and make the Linux comment about needingshell=Trueobsolete.
cmd = f"{sys.executable} -m flask run -p {port}"
if os.name == "nt": # On windows, subprocess creation works without being in the shell
child_process = subprocess.Popen(cmd, env=dict(os.environ))
else:
# On linux, have to set shell=True
child_process = subprocess.Popen(cmd, shell=True, preexec_fn=os.setsid, env=dict(os.environ))
kashifkhan
approved these changes
Mar 9, 2026
Member
Author
|
/check-enforcer override |
aprilk-ms
pushed a commit
that referenced
this pull request
Mar 11, 2026
Module level scoping caused the flask server to be started and stopped multiple times, causing flakiness. Make it session-scoped to only start it once. Signed-off-by: Paul Van Eck <paulvaneck@microsoft.com>
singankit
pushed a commit
that referenced
this pull request
Mar 16, 2026
Module level scoping caused the flask server to be started and stopped multiple times, causing flakiness. Make it session-scoped to only start it once. Signed-off-by: Paul Van Eck <paulvaneck@microsoft.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Module level scoping caused the flask server to be started and stopped multiple times, causing flakiness.
Make it session-scoped to only start it once.