Python Forum
Can I get a clue about testing please? - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Can I get a clue about testing please? (/thread-33272.html)



Can I get a clue about testing please? - Mustey - Apr-11-2021

I am picking up Python in a serious way, these days.
While reading through the syntax and standard libraries, I am also super-curious about the Python ecosystem.

In particular, I want to write code that is all unit-tested and then create repo's that enforce integration-testing.
Then, I want to have, like, functional testing suites for more end-to-end testing.

I have lots of experience with Java-JUnit-Maven and was wondering if Python adopts a similar build-test-deploy model or has some new patterns for me to learn?

Also, I've initially looked into the 'unittest' module. I've written some unit tests for my example application, ran those in the IDE, observed results... OK, that's cool :)

Then, I was interested in integrating my example application into a CI-CD system and wrote a little github workflow YAML file that sets up, builds and then runs tests - but that was using the 'pytest' module.

Is 'pytest' a "competitor" to 'unittest' or a complement (and, in that case, what is each used for?)?

'unittest' was kinda easy for me to understand, because it feels a lot like JUnit but in Python...
'pytest' was a little more obscure, as it uses a lot of standard folder and file names, which you need to know about in order to configure it correctly... But once I managed, it does look more sleek.

Yeah, I see my question is a bit broad and messy. I am just going to appreciate any discussion, idea, suggestion, etc :)


RE: Can I get a clue about testing please? - Larz60+ - Apr-12-2021

Have you read the python.org write-up?
If not start here: https://docs.python.org/3/library/unittest.html
Then there are many tutorial available which you can easily find with google.


RE: Can I get a clue about testing please? - Mustey - Apr-12-2021

Yes, that's where I started.
However, I was hoping for input from people who write commercial-grade code - for example: is 'unittest' preferable to 'pytest'?


RE: Can I get a clue about testing please? - Larz60+ - Apr-12-2021

I have written commercial software, and use python's unit test.
pytest was released on April 3 of this year.
I'll give it some time to prove itself before using.


RE: Can I get a clue about testing please? - Mustey - Apr-12-2021

oh wow, lucky me - I joined something before it became super common place - maybe I will be the leading pytest expert! :)

Thanks for that bit, it helps to make the right choice


RE: Can I get a clue about testing please? - Mustey - Apr-12-2021

ah, sorry, are we talking about the same thing:
https://docs.pytest.org/en/stable/changelog.html#changelog
("2009", etc...)


RE: Can I get a clue about testing please? - snippsat - Apr-12-2021

(Apr-12-2021, 09:40 AM)Larz60+ Wrote: pytest was released on April 3 of this year.
No and no⏰
pytest version 1.0.0 (2009-08-04)

For me it always pytest it reduces boilerplate code to the minimum,
and is much more pythonic than unittest which has to much flavors from Java JUnit.


RE: Can I get a clue about testing please? - buran - Apr-12-2021

(Apr-12-2021, 09:40 AM)Larz60+ Wrote: pytest was released on April 3 of this year.
I'll give it some time to prove itself before using.
well, pytest is well established test framework - ver 6.4.3 was release on 4 April 2021

@Mustey, I would say pytest is "competitor" to unittest (I hope you put same meaning). pytest is easy to start with and I like it. Give it a try.


RE: Can I get a clue about testing please? - Larz60+ - Apr-12-2021

OK, my mistake. I was looking at this page: https://pypi.org/project/pytest/
it shows release date: Apr 3, 2021, but I realize now that is for version 6.2.3