Best Python code snippet using avocado_python
ode_setup.py
Source:ode_setup.py  
1#!/usr/bin/env python32# -*- coding: utf-8 -*-3# Copyright (c) 2018 Bhojpur Consulting Private Limited, India. All rights reserved.4#5# Permission is hereby granted, free of charge, to any person obtaining a copy6# of this software and associated documentation files (the "Software"), to deal7# in the Software without restriction, including without limitation the rights8# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell9# copies of the Software, and to permit persons to whom the Software is10# furnished to do so, subject to the following conditions:11#12# The above copyright notice and this permission notice shall be included in13# all copies or substantial portions of the Software.14#15# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR16# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,17# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE18# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER19# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,20# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN21# THE SOFTWARE.22"""23   PyTest command class24   setup.py files in each package should include a cmdclass mapping25   from "test" to PyTest.26"""27import os28import sys29from setuptools.command.test import test as TestCommand30LIB = os.path.join("..", "..", "tests", "python")31sys.path.insert(0, LIB)32class PyTest(TestCommand):33    user_options = [34        ('test-path=', 't', "base dir for test collection"),35        ('test-pythonpath=', 'p', "prepend 'pythonpath' to PYTHONPATH"),36        ('test-ice-config=', 'i',37         "use specified 'ice config' file instead of default"),38        ('test-string=', 'k', "only run tests including 'string'"),39        ('test-marker=', 'm', "only run tests including 'marker'"),40        ('test-no-capture', 's', "don't suppress test output"),41        ('test-failfast', 'x', "Exit on first error"),42        ('test-verbose', 'v', "more verbose output"),43        ('test-quiet', 'q', "less verbose output"),44        ('junitxml=', None, "create junit-xml style report file at 'path'"),45        ('pdb', None, "fallback to pdb on error"),46        ('markers', None, "list available markers'"),47        ]48    def initialize_options(self):49        TestCommand.initialize_options(self)50        self.test_pythonpath = None51        self.test_ice_config = None52        self.test_string = None53        self.test_marker = None54        self.test_path = None55        self.test_no_capture = False56        self.test_failfast = False57        self.test_quiet = False58        self.test_verbose = False59        self.junitxml = None60        self.pdb = False61        self.markers = False62    def finalize_options(self):63        TestCommand.finalize_options(self)64        if self.test_path is None:65            self.test_path = 'test'66        self.test_args = [self.test_path]67        if self.test_string is not None:68            self.test_args.extend(['-k', self.test_string])69        if self.test_marker is not None:70            self.test_args.extend(['-m', self.test_marker])71        if self.test_no_capture:72            self.test_args.extend(['-s'])73        if self.test_failfast:74            self.test_args.extend(['-x'])75        if self.test_verbose:76            self.test_args.extend(['-v'])77        if self.test_quiet:78            self.test_args.extend(['-q'])79        if self.junitxml is not None:80            self.test_args.extend(['--junitxml', self.junitxml])81        if self.pdb:82            self.test_args.extend(['--pdb'])83        print(self.test_failfast)84        self.test_suite = True85        if self.markers:86            self.test_args = "--markers"87        if self.test_ice_config is None:88            self.test_ice_config = os.path.abspath('ice.config')89        if 'ICE_CONFIG' not in os.environ:90            os.environ['ICE_CONFIG'] = self.test_ice_config91    def run_tests(self):92        if self.test_pythonpath is not None:93            sys.path.insert(0, self.test_pythonpath)94        # import here, cause outside the eggs aren't loaded95        import pytest96        errno = pytest.main(self.test_args)...test_setup.py
Source:test_setup.py  
1#!/usr/bin/env python2# -*- coding: utf-8 -*-3"""4   PyTest command class5   setup.py files in each package should include a cmdclass mapping6   from "test" to PyTest.7   Copyright 2007-2013 Glencoe Software, Inc. All rights reserved.8   Use is subject to license terms supplied in LICENSE.txt9"""10import os11import sys12from setuptools.command.test import test as TestCommand13LIB = os.path.join("..", "..", "tests", "python")14sys.path.insert(0, LIB)15class PyTest(TestCommand):16    user_options = [17        ('test-path=', 't', "base dir for test collection"),18        ('test-pythonpath=', 'p', "prepend 'pythonpath' to PYTHONPATH"),19        ('test-ice-config=', 'i',20         "use specified 'ice config' file instead of default"),21        ('test-string=', 'k', "only run tests including 'string'"),22        ('test-marker=', 'm', "only run tests including 'marker'"),23        ('test-no-capture', 's', "don't suppress test output"),24        ('test-failfast', 'x', "Exit on first error"),25        ('test-verbose', 'v', "more verbose output"),26        ('test-quiet', 'q', "less verbose output"),27        ('junitxml=', None, "create junit-xml style report file at 'path'"),28        ('pdb', None, "fallback to pdb on error"),29        ('markers', None, "list available markers'"),30        ]31    def initialize_options(self):32        TestCommand.initialize_options(self)33        self.test_pythonpath = None34        self.test_ice_config = None35        self.test_string = None36        self.test_marker = None37        self.test_path = None38        self.test_no_capture = False39        self.test_failfast = False40        self.test_quiet = False41        self.test_verbose = False42        self.junitxml = None43        self.pdb = False44        self.markers = False45    def finalize_options(self):46        TestCommand.finalize_options(self)47        if self.test_path is None:48            self.test_path = 'test'49        self.test_args = [self.test_path]50        if self.test_string is not None:51            self.test_args.extend(['-k', self.test_string])52        if self.test_marker is not None:53            self.test_args.extend(['-m', self.test_marker])54        if self.test_no_capture:55            self.test_args.extend(['-s'])56        if self.test_failfast:57            self.test_args.extend(['-x'])58        if self.test_verbose:59            self.test_args.extend(['-v'])60        if self.test_quiet:61            self.test_args.extend(['-q'])62        if self.junitxml is not None:63            self.test_args.extend(['--junitxml', self.junitxml])64        if self.pdb:65            self.test_args.extend(['--pdb'])66        print self.test_failfast67        self.test_suite = True68        if self.markers:69            self.test_args = "--markers"70        if self.test_ice_config is None:71            self.test_ice_config = os.path.abspath('ice.config')72        if 'ICE_CONFIG' not in os.environ:73            os.environ['ICE_CONFIG'] = self.test_ice_config74    def run_tests(self):75        if self.test_pythonpath is not None:76            sys.path.insert(0, self.test_pythonpath)77        # import here, cause outside the eggs aren't loaded78        import pytest79        errno = pytest.main(self.test_args)...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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
