Giter Site home page Giter Site logo

Comments (3)

deathaxe avatar deathaxe commented on July 22, 2024

Waiting for a condition to continue test case execution (snippet 1) is fundamentally different from running an assertion (snippet 2).

A condition is something which must be met, but may take a while to do so due to asynchonously tasks needing to finish in background. It's main purpose is synchonization. The callable passed is polled until returning true. As self.assert... methods don't return anything and would raise exceptions if condition is not meat they are not applicable in this context.

Conditions can be passed as dictionary. Maybe passing an optional error message can be implemented, which is displayed if timeout appears.

    def test_something(self):
        self.window.run_command("show_panel", {"panel": "console"})
        yield { 
            "condition": lambda: self.window.active_panel() == "console",
            "period": 100,
            "timeout": 5000,
            "timeout_message": "Console not activated"
        }

from unittesting.

giampaolo avatar giampaolo commented on July 22, 2024

The callable passed is polled until returning true. As self.assert... methods don't return anything and would raise exceptions if condition is not meat they are not applicable in this context.

My proposal was to keep catching AssertionError as a synchronization mechanism as in:

def call_until(assert_call, timeout=5):
    stop_at = time.monotonic() + timeout
    while True:
        try:
            return assert_call()
        except AssertionError:
            if time.monotonic() > stop_at:
                raise TimeoutError
            time.sleep(0.01)

from unittesting.

deathaxe avatar deathaxe commented on July 22, 2024

Interesting idea. When assuming assertions to always return None and normal conditions only True or False, it should be doable with hopefully low risk on breaking anyones test cases.

Was too focused on "missing a message" and the aspect of conditions vs. assertions, before.

from unittesting.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.