Python, unit test - Pass command line arguments to setUp of unittest.TestCase

前端 未结 4 1451
情书的邮戳
情书的邮戳 2020-12-08 03:02

I have a script that acts as a wrapper for some unit tests written using the Python unittest module. In addition to cleaning up some files, creating an output s

4条回答
  •  遥遥无期
    2020-12-08 03:08

    I would definitely advise against passing arguments to setUp like this; setUp is intended to be called implicitly when running a test, so you shouldn't be explicitly calling it like this.

    One way you could tackle this would be to set the values you need to set either as environment variables or values in a globally accessible "context" module, which would allow test cases to access them as needed. I would go for using environment variables, as it is more flexible in terms of running the tests (you're then no longer relying on command line arguments).

提交回复
热议问题