How to use test_skip_decorators method in avocado

Best Python code snippet using avocado_python

test_skip_decorators.py

Source: test_skip_decorators.py Github

copy

Full Screen

1# coding=utf-82# Copyright 2019-present, the HuggingFace Inc. team.3#4# Licensed under the Apache License, Version 2.0 (the "License");5# you may not use this file except in compliance with the License.6# You may obtain a copy of the License at7#8# http:/​/​www.apache.org/​licenses/​LICENSE-2.09#10# Unless required by applicable law or agreed to in writing, software11# distributed under the License is distributed on an "AS IS" BASIS,12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13# See the License for the specific language governing permissions and14# limitations under the License.15#16#17#18# this test validates that we can stack skip decorators in groups and whether19# they work correctly with other decorators20#21# since the decorators have already built their decision params (like checking22# env[], we can't mock the env and test each of the combinations), so ideally23# the following 4 should be run. But since we have different CI jobs running24# different configs, all combinations should get covered25#26# RUN_SLOW=1 pytest -rA tests/​test_skip_decorators.py27# RUN_SLOW=1 CUDA_VISIBLE_DEVICES="" pytest -rA tests/​test_skip_decorators.py28# RUN_SLOW=0 pytest -rA tests/​test_skip_decorators.py29# RUN_SLOW=0 CUDA_VISIBLE_DEVICES="" pytest -rA tests/​test_skip_decorators.py30import os31import unittest32import pytest33from parameterized import parameterized34from transformers.testing_utils import require_torch, require_torch_gpu, slow, torch_device35# skipping in unittest tests36params = [(1,)]37# test that we can stack our skip decorators with 3rd party decorators38def check_slow():39 run_slow = bool(os.getenv("RUN_SLOW", 0))40 if run_slow:41 assert True42 else:43 assert False, "should have been skipped"44# test that we can stack our skip decorators45def check_slow_torch_cuda():46 run_slow = bool(os.getenv("RUN_SLOW", 0))47 if run_slow and torch_device == "cuda":48 assert True49 else:50 assert False, "should have been skipped"51@require_torch52class SkipTester(unittest.TestCase):53 @slow54 @require_torch_gpu55 def test_2_skips_slow_first(self):56 check_slow_torch_cuda()57 @require_torch_gpu58 @slow59 def test_2_skips_slow_last(self):60 check_slow_torch_cuda()61 # The combination of any skip decorator, followed by parameterized fails to skip the tests62 # 1. @slow manages to correctly skip `test_param_slow_first`63 # 2. but then `parameterized` creates new tests, with a unique name for each parameter groups.64 # It has no idea that they are to be skipped and so they all run, ignoring @slow65 # Therefore skip decorators must come after `parameterized`66 #67 # @slow68 # @parameterized.expand(params)69 # def test_param_slow_first(self, param=None):70 # check_slow()71 # This works as expected:72 # 1. `parameterized` creates new tests with unique names73 # 2. each of them gets an opportunity to be skipped74 @parameterized.expand(params)75 @slow76 def test_param_slow_last(self, param=None):77 check_slow()78# skipping in non-unittest tests79# no problem at all here80@slow81@require_torch_gpu82def test_pytest_2_skips_slow_first():83 check_slow_torch_cuda()84@require_torch_gpu85@slow86def test_pytest_2_skips_slow_last():87 check_slow_torch_cuda()88@slow89@pytest.mark.parametrize("param", [1])90def test_pytest_param_slow_first(param):91 check_slow()92@pytest.mark.parametrize("param", [1])93@slow94def test_pytest_param_slow_last(param):...

Full Screen

Full Screen

Blogs

Check out the latest blogs from LambdaTest on this topic:

Nov’22 Updates: Live With Automation Testing On OTT Streaming Devices, Test On Samsung Galaxy Z Fold4, Galaxy Z Flip4, & More

Hola Testers! Hope you all had a great Thanksgiving weekend! To make this time more memorable, we at LambdaTest have something to offer you as a token of appreciation.

Considering Agile Principles from a different angle

In addition to the four values, the Agile Manifesto contains twelve principles that are used as guides for all methodologies included under the Agile movement, such as XP, Scrum, and Kanban.

How To Choose The Best JavaScript Unit Testing Frameworks

JavaScript is one of the most widely used programming languages. This popularity invites a lot of JavaScript development and testing frameworks to ease the process of working with it. As a result, numerous JavaScript testing frameworks can be used to perform unit testing.

How To Write End-To-End Tests Using Cypress App Actions

When I started writing tests with Cypress, I was always going to use the user interface to interact and change the application’s state when running tests.

[LambdaTest Spartans Panel Discussion]: What Changed For Testing & QA Community And What Lies Ahead

The rapid shift in the use of technology has impacted testing and quality assurance significantly, especially around the cloud adoption of agile development methodologies. With this, the increasing importance of quality and automation testing has risen enough to deliver quality work.

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run avocado automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful