There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply () below.
If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.
Join the Discussion. Help a fellow learner on their journey.
Ask or answer a question about this exercise by clicking reply () below!
You can also find further discussion and get answers to your questions over in Language Help.
Agree with a comment or answer? Like () to up-vote the contribution!
Power cycling bluetooth device… Testing Feature A Power cycling bluetooth device… Power cycling bluetooth device… Testing Feature B Power cycling bluetooth device…
Your questions tie together somewhat so I’ll try to answer them both at once. We get that output because the methods setUp and tearDown are called before every test we perform.
So we have the first test test_feature_a which behaves in the following way- setUp() → Power cycling bluetooth device… test_feature_a() → Testing Feature A tearDown() → Power cycling bluetooth device…
Then the second test: setUp() → Power cycling bluetooth device… test_feature_b() → Testing Feature B tearDown() → Power cycling bluetooth device…
Using the setUpClass as a class method means this method is called once before any testing is run and tearDownClass is run after all the tests are complete. So the biggest difference is when and how often these methods are called.
setUpClass() → Power cycling bluetooth device… test_feature_a() → Testing Feature A test_feature_b() → Testing Feature B tearDownClass() → Power cycling bluetooth device…
I did not understand the purpose of decorator here. Why do we put @classmethod above setUpClass ?
As I remember from video-explanation from Mike What Are Decorators? - YouTube we using wrapper() to “boost” decorating method/function passing it name after “@”. But what are we wrapping in setUpClass with decorator @classmethod?
It’s a bit of a guess but I think the implementation is such that every defined test is performed on a new instance of this testing class. So .setUp and .tearDown and run for each and every new instance, whereas we want the set-up to be available for every possible new instance so we use @classmethod around .setUpClass to modify the class itself. I’ve not looked too closely at the implementation of testtunit so I could be wrong. If you wanted a definite you might have to search elsewhere.
Struggling to figure out why the @classmethod decorator is needed here and how it does what it does.
Does decorating the setUpClass and tearDownClass methods with the @classmethod decorator simply mean that those methods will be run before and after an instance of the class whenever the instance is run? As opposed to running before and after each method?
Documentation I have found regarding the @classmethod decorator only furthers my confusion.