0

I have a python code file like below.I want to use the list created in fun1 as data input to the 2nd pytest marker. But when I am running this code. parametrize marker is not able to access this list. Thats why pytest is skipping this 2nd test. I made this list as global so that 2nd test func could access it.Looking for suggestions

@pytest.mark.parametrize("param1,param2",[(a,b),(c,d)])
def test_func1(parm1, param 2):


   #creating a new list in this function
   New_list


@pytest.mark.parametrize("param3,param4",New_list)
def test_func2(param3, param4) :
Stavinsky
  • 323
  • 4
  • 11
  • 1
    If I understood you question it is not very good to share variables between tests. Tests should be atomic. And every test should clean up after himself. I believe you should reconsider your testing process – Stavinsky Nov 21 '19 at 14:55
  • but my 2nd test depends on the data returned from first tests.I do have other ways to do it. Just wanted to make sure whether I can achieve it this way or not. – Kanchan Mittal Nov 21 '19 at 15:00
  • First of all: you can run more than one test in same time. So it is possible situation that your func2 will run before func1. (I'm not sure in 100% but I believe it is true) So I would recommend make all the tests on the "New_list" as multiple asserts in one test. Especially if you need to follow the sequence. Please correct me about concurency if I'm wrong – Stavinsky Nov 21 '19 at 15:07
  • I need to follow the sequence and as per my understanding pytest also executing both functions sequentially. first test_func1 is executing then test_func2 – Kanchan Mittal Nov 21 '19 at 15:14
  • 1
    Please read this [question](https://stackoverflow.com/questions/17571438/test-case-execution-order-in-pytest) also – Stavinsky Nov 21 '19 at 15:16
  • 1
    What you are trying to achieve is not possible. Markers are just decorators and the decorators are resolved on import, when no code has executed at all. Create and fill `New_list` on module level, then pass it to both tests. – hoefling Nov 21 '19 at 15:59
  • thanks for the suggestion.It certainly helped – Kanchan Mittal Nov 21 '19 at 16:46

0 Answers0