Open alphaCTzo7G opened 6 years ago
Hey @alphaCTzo7G thanks for the compliment. Glad to hear you enjoyed the post! Moving on to the questions:
I'm not sure I understand the question / whether I am capable of answering it. If you're referring to the test and application layout/structure, you can get more insight into the question / potential solutions by reading this section of the Pytest docs If this still doesn't answer the question, please add a comment clarifying more on the exact question, then I'll see how I can help.
I noticed that even though the boilerplate code did decrease, when you used test fixtures, the total number of lines of code actually increased. Are test fixtures primarily used when you have larger libraries? How do you decide when to start using test-fixtures?
I'm going to give a very generic answer here: It depends 😃 It's all a matter of using what works best for you. If the fixtures help you understand the tests better / increase your productivity, then use more of them, if not, use less / none of them. It all boils down to a mix of personal preference and the needs of the project.
I noticed that you have a module named wallet, a class named Wallet and a variable named wallet. I may be wrong, but wouldnt it be better to have different names, or is this best practice?
My naming here is is horribly wrong 🤦♂️ It is much better to have different names that describe the different items as closely as possible. This was a huge mistake on my part. Thanks for pointing it out.
And in the capital_case
function, that was indeed a typo.
Thanks for all the feedback @alphaCTzo7G 👍
Hi Kevin,
Thanks for this great article. It gave me a great understanding of pytest, parameterizing pytest and creating fixtures.
Question 1:
There is a difference between
import
-ing and running a function in a python module, at theipython
command prompt and using the%run/run
to run a module at the command prompt, in how python sets thesys.path
, and hence whether certain modules will be imported and whether the test function will work or not.In the case you pointed, out
capital_case
andtest_capital_case
are in the same module. Similarly,wallet.py
andtest_wallet.py
are in the same directory. So regardless of whether pytestimport
-s orrun
-s the functions in thetest_wallet
module, it shouldn’t have problems. However, if yourtest_module.py
andmodule.py
are located in different directories, and depending on the directory structure where they are located arun
statement andimport
statement will see differentsys.path
and could thus fail.So I know how to write the import statements, if the
test_module
andmodule
are located in different directories, I wonder ifpytest
actually does something similar to arun test_module.py
or more likeimport test_module.test_function()
?Question2:
I noticed that even though the boilerplate code did decrease, when you used test fixtures, the total number of lines of code actually increased. Are test fixtures primarily used when you have larger libraries? How do you decide when to start using test-fixtures?
Question3:
I noticed that you have a
module
namedwallet
, aclass
namedWallet
and avariable
namedwallet
. I may be wrong, but wouldnt it be better to have different names, or is this best practice?Potential Correction:
I noticed that in the following function, there is an extra space before return:
Perhaps thats a typo. I thought it would be helpful if I pointed it out so, its slightly more clear for new python coders.
Thanks again for writing this tutorial!