Skip to content

test examples#2697

Draft
ElLorans wants to merge 1 commit into
masterfrom
feat/test-examples
Draft

test examples#2697
ElLorans wants to merge 1 commit into
masterfrom
feat/test-examples

Conversation

@ElLorans

@ElLorans ElLorans commented Nov 3, 2025

Copy link
Copy Markdown
Contributor

fixes #2470

@ElLorans

ElLorans commented Nov 3, 2025

Copy link
Copy Markdown
Contributor Author

Locally the new tests are much faster, not sure how to tackle this

@samuelhwilliams

Copy link
Copy Markdown
Contributor

6 hours 😂 😭 yeah something doesn't feel quite right ha. Not sure when I can help out with investigating this but can try to 👍

@ElLorans

ElLorans commented Nov 4, 2025

Copy link
Copy Markdown
Contributor Author

6 hours 😂 😭 yeah something doesn't feel quite right ha. Not sure when I can help out with investigating this but can try to 👍

locally most tests pass (I still have to verify that they do not if I add an error to the examples), probably subprocess.Popen and requests.get are not supported by github actions. I need to find a new way, I probably just overnengineered it and I can simply build a dynamic test matrix with tox.

@samialfattani

samialfattani commented Nov 4, 2025

Copy link
Copy Markdown
Contributor

I have tried an approach like this but i could not make it to succesfful run, have a look it might be an idea. Assuming that all examples should have create_app() function that returns the Flask app object.

@pytest.mark.parametrize("example_name,example_path", get_example_directories())
def test_example_runs(example_name: str, example_path: Path):
    """
    Test that the example can be started and that the /admin endpoint returns HTTP 200.

    Args:
        example_name: Name of the example.
        example_path: Path to the example directory.
    """

    def run_tester(app):
        try:
            # Wait for the server to start
            time.sleep(2)

            Check if the /admin endpoint is reachable
            response = requests.get("http://localhost:5000/admin")
            assert (
                response.status_code == 200
            ), f"/admin endpoint returned {response.status_code}"

        finally:
            app.sutdown()
            print(f"Example '{example_name}' ran successfully.")

    sys.path.append(str(example_path))
    from main import create_app

    app = create_app()

    import threading

    thread = threading.Thread(target=run_tester, args=(app), daemon=True)
    thread.start()

    # app.run(debug=True)

@ElLorans

ElLorans commented Nov 5, 2025

Copy link
Copy Markdown
Contributor Author

Unfortunately, this does not work because each example needs its own env

@hasansezertasan

Copy link
Copy Markdown
Member

Unfortunately, this does not work because each example needs its own env

WDYT about #2470 (comment)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

Add a test that runs all of the examples

4 participants