Preface

In the last article, we talked about pytest Naming rules of test cases in , So in pytest In what order are the test cases executed in ?

stay unittest In the frame , The default in accordance with the ACSII Load test cases in the order of code and execute , In sequence :09、AZ、a~z, Test directory 、 Test module 、 Test class 、 The test method / Test functions load test cases according to this rule .

and pytest The execution sequence of use cases in is the same as unittest It's different ,pytest There is a default execution order , You can also customize the execution order .

pytest Default execution order

  • Test directory 、 Test module , Execute in sort order

    The order of execution is as follows :

  • Execution sequence under the same test module

    import pytest
    
    class TestOrder:
    
        def test_e(self):
    print("test_e") def test_4(self):
    print("test_4") def test_b():
    print("test_a") def test_a():
    print("test_a") def test_2():
    print("test_2") def test_1():
    print("test_1") if __name__ == '__main__':
    pytest.main()

    The order of execution is as follows :

Custom execution order

pytest The framework supports the execution sequence of custom test cases , Need to install pytest-ordering plug-in unit .

install

pip install pytest-ordering

Use

Need to use @pytest.mark.run(), The code is as follows :

import pytest

class TestOrder:

    def test_e(self):
print("test_e") def test_4(self):
print("test_4") def test_b():
print("test_a") @pytest.mark.run(order=2)
def test_a():
print("test_a") @pytest.mark.run(order=1)
def test_2():
print("test_2") def test_1():
print("test_1") if __name__ == '__main__':
pytest.main()

The order of execution is as follows :

In the test module , First of all, to be @pytest.mark.run() Marking test methods / Test functions , Then perform other tasks in the default order .

summary

although pytest You can customize the execution order of test cases , But in the process of actual test case design , Use cases should not be executed in sequence , That is, any individual test case is an independent and complete verification of function points , Not dependent on other use cases .

pytest(4)- More related articles on the execution sequence of test cases

  1. Use TestNG The execution sequence of framework test cases

    Since it's about the order of execution , Then the use cases must be executed in batches , The methods of batch execution are mvn test. Direct operation testng.xml file , Which runs directly testng.xml Document effect and pom Configuration execution in file testng.xm ...

  2. pytest frame - Introduce 、Mark( tagging )、 The command runs the use case 、 Use case execution sequence 、

    1.pytest Introduce : be based on unittest The unit testing framework above 1.1. Automatic discovery of test modules and test cases : unitest You need to add use cases ,( Taist house loan ) Loaders load test cases pytest Just one piece of code ...

  3. 【pytest Official documents 】 Reading fixtures - 11. fixture Execution order of ,3 Details of elements ( Long warning )

    When pytest To execute a test function , This test function also requests fixture function , So at this point pytest We need to make sure that fixture The order of execution is changed . There are three factors : scope, Namely fixture The scope of the function , Than ...

  4. python Interface automation ( Twenty-two )--unittest Execution order hidden pits ( Detailed explanation )

    brief introduction Most beginners are using unittest Frame time , It's not clear what the execution order of use cases is . I don't know the classes and methods in the test class , I don't know when to execute , When not to execute . Although perhaps through the code to achieve , It's also a confused knowledge ...

  5. pytest- Adjust the execution order of test cases

    scene : When execution in natural order is not considered , Or want to change the order of execution , For example, increase Data use cases need to be executed first , Then execute the deleted use case . The default test case is by name It's called sequential execution . • solve : • install :pip install pytest-orde ...

  6. pytest The execution order of use cases

    Pytest Order of execution When pytest When you run the test function , It looks at the parameters in the test function , Then search for... With the same name as these parameters fixture. once pytest Find these objects , It will run these fixture Affect the smooth implementation ...

  7. unittest Execution order of test cases

    unittest The test sequence of is : There are several test cases , How many times will the firmware be tested . for example : When there is only one test case : setup--testcase1--teardown import unittest class F ...

  8. Python+selenium And unittest unit testing (3) About the sequence of test case execution

    One . The order in which test cases are executed The sequence of use case execution involves multiple levels , In the case of multiple test directories , Which directory to execute first ? In the case of multiple test files , Which file to execute first ? In the case of multiple test classes , Which test class to execute first ?, In multiple test methods ( Use cases ) Sentiment ...

  9. Selenium actual combat ( Four )——unittest unit testing 3( Execution order of test cases )

    One . Execution order of test cases Hierarchy : Multiple test directories > Multiple test files > Multiple test classes > Multiple test methods ( The test case ). Here, take a script that tests the execution sequence as an example test_order.py import ...

  10. Pytest_ Use case execution sequence (5)

    stay unittest in , The execution order of test cases is related to the name of test cases , By name ascii Code ordered , It is not executed in the order in which the use cases are written . pytest By default, it is executed according to the writing order of use cases We can use third-party packages  pytes ...

Random recommendation

  1. Immutable.js – JavaScript Immutable data sets

    Immutable data is data that cannot be modified once created , Make application development easier , Allows the use of functional programming techniques , Like inertia assessment .Immutable JS Provide an inert Sequence, Allows efficient chain of queued methods , similar map and f ...

  2. Java character string split Function considerations

    Java A string of split Method to split a string , But unlike other languages ,split The argument to the method is not a single character , It's regular expressions , If you enter a vertical line (|) Such characters are used as split strings , There will be unexpected results , Such as , Str ...

  3. Second articles : Miscellaneous image processing pillow

    Miscellaneous image processing pillow   Miscellaneous image processing pillow Content of this section reference Generate verification code source code Some small examples 1. reference http://pillow-cn.readthedocs.io/zh_CN/ ...

  4. BZOJ 3122 Random number generator

    http://www.lydsy.com/JudgeOnline/problem.php?id=3122 The question : give p,a,b,x1,t It is known that xn=a*xn-1+b%p, Minimum n Make xn=t First , if ...

  5. Redis + Jedis + Spring example ( Operations on objects )

        Catalog (?)[+] Have to say , Using hash operations to store objects , It's kind of asking for trouble ! however , Now that I have suffered , And make a note , Maybe later API After upgrading , It's easier to use ?! Maybe , It's my misunderstanding , No real understanding of hash tables . One . expect Connect ...

  6. #include<math.h>

    1.sin(a) class :a Is the radian value : 2.abs(b): The result is b The absolute value of : 3.exp(c):exp() Used to calculate to e At the bottom of the x The power is , namely ex value , Then return the result to . Return value : return e Of x Power calculation result . 4.log ...

  7. C The guessing game of language

    #include<stdio.h>#include<stdlib.h>#include<time.h>int main(){ srand(time(0)); int ...

  8. Python_day1

    One .HelloWorld >>>print("Hello World!") >>>Hello World! Two . Variable    1. What is a variable : ...

  9. Mycat Configuration instructions (rule.xml)

    rule.xml The configuration file defines the rules that we need to split the table . We can flexibly use different slicing algorithms for tables , Or use the same algorithm for the table, but the specific parameters are different . tableRule label This label is used to define the table's splitting rules ...

  10. Read a text Transformer internals ( contain PyTorch Realization )

    Transformer Notes and PyTorch Realization original text :http://nlp.seas.harvard.edu/2018/04/03/attention.html author :Alexander Rush turn ...