2

I want to desgin some test case, each test case will do the same operation like

testA do:

insomd moduleX
testing
rmmod moduleX

testB do

insomd moduleY
testing
rmmod moduleY

is it possilbe to put insmod and rmmod operation into setup and teardown? by parameter or something like that. I want to use setup/teardown to do the prepare and cleanup operation here but not in the test function.

user1334609
  • 381
  • 4
  • 12
  • Possible duplicate of [Explain the "setUp" and "tearDown" Python methods used in test cases](https://stackoverflow.com/questions/6854658/explain-the-setup-and-teardown-python-methods-used-in-test-cases) – nimish Jun 08 '18 at 13:28

1 Answers1

0

Sure, just import os and run os.system('insmod moduleX') and os.system('rmmod moduleX') in your setup and teardown for testA, and mutatis mutandis for testB.

Take a look here for how to call external commands in python.

You're going to be changing the os, so if something interrupts your tests before teardown occurs, you could leave your system in an inconsistent state.

nimish
  • 4,755
  • 3
  • 24
  • 34
  • no, I'm not asking if I can put shell command in python script, I'm ask how to use setup and teardown to do the different thing for different test case – user1334609 Jun 08 '18 at 05:39
  • You would need to move them to different test suites. – nimish Jun 08 '18 at 13:28