Coder Social home page Coder Social logo

How to do conditional Skip? about testslide HOT 7 CLOSED

facebook avatar facebook commented on April 27, 2024
How to do conditional Skip?

from testslide.

Comments (7)

fornellas avatar fornellas commented on April 27, 2024

https://testslide.readthedocs.io/en/1.5.0/testslide_dsl/skip_and_focus/index.html#skip

xexample is the way to go for unconditional skip. However it is just regular Python, this also works:

if should_have_example:
  @context.example
  def whatever(self):

Real world example https://github.com/facebookincubator/TestSlide/blob/master/tests/mock_callable_testslide.py#L179.

I suppose we could have some syntax sugar for that like:

@context.example(skip=should_skip)

But it seems no to be strictly needed.

What do you think?

from testslide.

xush6528 avatar xush6528 commented on April 27, 2024

The daily use case for my work is that we have some test examples that only runs on GPU CUDA devices.

But CI could pick building and testing our project in either environment, ones with CPU+GPU or ones that has CPU only.

We used @unittest.skipUnless(cuda.is_available()) a lot.

In TestSlide, we will have to write this to circumvent

If not cuda.is_available():
    return

And, more importantly, the test runner will not remind me that the test is skipped.

from testslide.

xush6528 avatar xush6528 commented on April 27, 2024

@fornellas Thanks, I will try this way. Conditionally declare contexts and examples.

from testslide.

fornellas avatar fornellas commented on April 27, 2024

Cool. I'm closing this then, as it seems you have a way for conditionally skip. Feel free to reopen if you feel like it deserves some syntax sugar.

from testslide.

xush6528 avatar xush6528 commented on April 27, 2024

After trying it out, I feel it's still needed.

Because it would be great to have a "SKIP" item in test runner results, just like @context.xexample does.

In short, skipped tests are worth being noticed!

For example, I have a lot of tests that must be skipped when running on a machine without GPU avaiable.
With conditional test example declaration as you suggested above would silently hide these examples.

However, for a new developer onboarding to my tests, he/she might be unware of that, when running on a CPU only machine, there are many GPU tests being explicitly skipped.

If these skipped tests could be noticed by new developmers, they might find better test environment.

from testslide.

fornellas avatar fornellas commented on April 27, 2024

NP. So, how do you think the syntax should go?

@context.example(skip=should_skip)

Is it ok like this?

from testslide.

xush6528 avatar xush6528 commented on April 27, 2024

Thanks for opening it.

It looks great.

One thing worth noticing is that, after searching in my company's repo, I noticed that @unittest.skipUnless(condition) has 2X usage than @unittest.skip(condition).

That means with this simple syntax, we need to expect a lot of

@context.example(skip=not should_run_example)

from testslide.

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.