Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #95524 > unrolled thread

Parametrized Unit Tests

Started byrambius <rambiusparkisanius@gmail.com>
First post2015-08-21 08:17 -0700
Last post2015-08-29 21:34 -0700
Articles 14 — 10 participants

Back to article view | Back to comp.lang.python


Contents

  Parametrized Unit Tests rambius <rambiusparkisanius@gmail.com> - 2015-08-21 08:17 -0700
    Re: Parametrized Unit Tests Laura Creighton <lac@openend.se> - 2015-08-21 17:42 +0200
    Re: Parametrized Unit Tests Ben Finney <ben+python@benfinney.id.au> - 2015-08-22 11:42 +1000
      Re: Parametrized Unit Tests rambius <rambiusparkisanius@gmail.com> - 2015-08-27 07:38 -0700
        Re: Parametrized Unit Tests Ben Finney <ben+python@benfinney.id.au> - 2015-08-28 09:46 +1000
          OFF-TOPIC Ben's sig monster quote [was Re: Parametrized Unit Tests] Steven D'Aprano <steve@pearwood.info> - 2015-08-28 16:26 +1000
            Re: OFF-TOPIC Ben's sig monster quote [was Re: Parametrized Unit Tests] Martin Skjöldebrand <martin@skjoldebrand.eu> - 2015-08-28 09:19 +0200
            Re: OFF-TOPIC Ben's sig monster quote [was Re: Parametrized Unit Tests] Ben Finney <ben+python@benfinney.id.au> - 2015-08-28 17:27 +1000
              Re: OFF-TOPIC Ben's sig monster quote [was Re: Parametrized Unit Tests] Marko Rauhamaa <marko@pacujo.net> - 2015-08-28 12:24 +0300
                Re: OFF-TOPIC Ben's sig monster quote [was Re: Parametrized Unit Tests] jmp <jeanmichel@sequans.com> - 2015-08-28 11:47 +0200
            Re: OFF-TOPIC Ben's sig monster quote [was Re: Parametrized Unit Tests] Steven D'Aprano <steve@pearwood.info> - 2015-08-29 00:02 +1000
              Re: OFF-TOPIC Ben's sig monster quote [was Re: Parametrized Unit Tests] Chris Angelico <rosuav@gmail.com> - 2015-08-29 01:07 +1000
            Re: OFF-TOPIC Ben's sig monster quote [was Re: Parametrized Unit Tests] Michael Torrie <torriem@gmail.com> - 2015-08-28 14:00 -0600
            Re: OFF-TOPIC Ben's sig monster quote [was Re: Parametrized Unit Tests] Rustom Mody <rustompmody@gmail.com> - 2015-08-29 21:34 -0700

#95524 — Parametrized Unit Tests

Fromrambius <rambiusparkisanius@gmail.com>
Date2015-08-21 08:17 -0700
SubjectParametrized Unit Tests
Message-ID<f2d05b33-8755-4270-9bf4-b0b6153d13f7@googlegroups.com>
Hello,

I am running one and the same unit tests that test some web application. I would like to execute them against different servers that may host different instances of the application.

So far I have something like

#!/usr/bin/env python

import unittest

server = ""
user = ""
password = ""

class MyTest(unittest.TestCase):

    def setUp(self):
        global server
        global user
        global password
        self.conn = MyConnection(server, user, password)

    def test_1(self):
        result = run_smth_1(self.conn)
        verify_smth_1(result)

    def test_2(self):
        result = run_smth_2(self.conn)
        verify_smth_2(result)

    def tearDown(self):
        self.conn.close()


if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument('-u', '--user',
                        default=getpass.getuser())
    parser.add_argument('-p', '--password')
    parser.add_argument('-s', '--server')
    args = parser.parse_args()

    server = args.server
    user = args.user
    password = args.password

    unittest.main()


Is there a better a way to pass the server, the user and the password to the test without resolving to global variables?

Although I developed these tests as unit tests they are more of integration tests. Is there an integration testing framework that supports a more convenient passing of test parameters / data?

Thank you in advance for your responses.

Regards
Rambius

[toc] | [next] | [standalone]


#95525

FromLaura Creighton <lac@openend.se>
Date2015-08-21 17:42 +0200
Message-ID<mailman.10.1440171757.13558.python-list@python.org>
In reply to#95524
In a message of Fri, 21 Aug 2015 08:17:32 -0700, rambius writes:
>Although I developed these tests as unit tests they are more of integration tests. Is there an integration testing framework that supports a more convenient passing of test parameters / data?
>
>Thank you in advance for your responses.
>
>Regards
>Rambius

Many. https://wiki.python.org/moin/PythonTestingToolsTaxonomy isn't
a bad place to start looking, but things have been developed which
aren't there.  ie responses 
http://cramer.io/2014/05/20/mocking-requests-with-responses/
nice thing for mocking requests, if you are using the requests
library ...


You may get a better response if you try that question over here:
http://lists.idyll.org/listinfo/testing-in-python

Laura

[toc] | [prev] | [next] | [standalone]


#95543

FromBen Finney <ben+python@benfinney.id.au>
Date2015-08-22 11:42 +1000
Message-ID<mailman.9.1440207786.17298.python-list@python.org>
In reply to#95524
rambius <rambiusparkisanius@gmail.com> writes:

> I am running one and the same unit tests that test some web
> application. I would like to execute them against different servers
> that may host different instances of the application.

Those aren't unit tests, then. A unit test, by definition, tests a small
unit of code; usually one true-or-false assertion about one function
call.

What you describe sounds more like integration tests or feature tests or
acceptance tests; something where large parts of the code base are all
exercised at once.

> Is there a better a way to pass the server, the user and the password
> to the test without resolving to global variables?

The ‘testscenarios’ library is one way to have a set of scenarios
applied at run-time to produce tests across all combinations
<URL:https://pypi.python.org/pypi/testscenarios/>.

> Although I developed these tests as unit tests they are more of
> integration tests. Is there an integration testing framework that
> supports a more convenient passing of test parameters / data?

You may want to look at behaviour-driven testing, e.g. using Behave
<URL:https://pypi.python.org/pypi/behave/>.

Another resource to use is the ‘testing-in-python’ forum
<URL:http://lists.idyll.org/listinfo/testing-in-python> where there is
more focussed discussion on testing in Python.

-- 
 \       “Repetition leads to boredom, boredom to horrifying mistakes, |
  `\       horrifying mistakes to God-I-wish-I-was-still-bored, and it |
_o__)              goes downhill from there.” —Will Larson, 2008-11-04 |
Ben Finney

[toc] | [prev] | [next] | [standalone]


#95695

Fromrambius <rambiusparkisanius@gmail.com>
Date2015-08-27 07:38 -0700
Message-ID<0c60848a-5bc2-42d3-8062-57d166fea298@googlegroups.com>
In reply to#95543
Hello,

петък, 21 август 2015 г., 21:43:19 UTC-4, Ben Finney написа:
> > Is there a better a way to pass the server, the user and the password
> > to the test without resolving to global variables?
> 
> The ‘testscenarios’ library is one way to have a set of scenarios
> applied at run-time to produce tests across all combinations
> <URL:https://pypi.python.org/pypi/testscenarios/>.

testscenarios worked for me. Thank you for your recommendation.

Regards
Ivan

[toc] | [prev] | [next] | [standalone]


#95713

FromBen Finney <ben+python@benfinney.id.au>
Date2015-08-28 09:46 +1000
Message-ID<mailman.93.1440719179.11709.python-list@python.org>
In reply to#95695
rambius <rambiusparkisanius@gmail.com> writes:

> Hello,
>
> петък, 21 август 2015 г., 21:43:19 UTC-4, Ben Finney написа:
> > The ‘testscenarios’ library is one way to have a set of scenarios
> > applied at run-time to produce tests across all combinations
> > <URL:https://pypi.python.org/pypi/testscenarios/>.
>
> testscenarios worked for me. Thank you for your recommendation.

You're welcome! You may be interested in the ‘testing-in-python’ forum
<URL:http://lists.idyll.org/listinfo/testing-in-python> to discuss other
aspects of writing test cases in Python.

-- 
 \        “Of course, everybody says they're for peace. Hitler was for |
  `\      peace. Everybody is for peace. The question is: what kind of |
_o__)                                peace?” —Noam Chomsky, 1984-05-14 |
Ben Finney

[toc] | [prev] | [next] | [standalone]


#95726 — OFF-TOPIC Ben's sig monster quote [was Re: Parametrized Unit Tests]

FromSteven D'Aprano <steve@pearwood.info>
Date2015-08-28 16:26 +1000
SubjectOFF-TOPIC Ben's sig monster quote [was Re: Parametrized Unit Tests]
Message-ID<55dfff1b$0$1652$c3e8da3$5496439d@news.astraweb.com>
In reply to#95713
Completely off-topic. Stop reading now if you only want to read things about
Python.


On Fri, 28 Aug 2015 09:46 am, Ben Finney wrote:

> \        “Of course, everybody says they're for peace. Hitler was for |
> `\      peace. Everybody is for peace. The question is: what kind of |
> _o__)                                peace?” —Noam Chomsky, 1984-05-14 |


With the greatest of respect to Chomsky, I think he is simply wrong about
Hitler. Hitler actually believed that war was good for the national
character, and indeed good for the soul, and that long periods of peace
would enfeeble a nation and make it decadent and effete. Unlike a lot of
people who believe the same thing, Hitler actually had experience in war,
including a medal for bravery and a serious injury due to poison gas.

Many people over the ages have thought that if only war was more terrible,
we would stop making it. Alas, that appears to be false: no matter how
terrible war is, there is always someone who thinks that it is better than
peace.



-- 
Steven

[toc] | [prev] | [next] | [standalone]


#95728 — Re: OFF-TOPIC Ben's sig monster quote [was Re: Parametrized Unit Tests]

FromMartin Skjöldebrand <martin@skjoldebrand.eu>
Date2015-08-28 09:19 +0200
SubjectRe: OFF-TOPIC Ben's sig monster quote [was Re: Parametrized Unit Tests]
Message-ID<mailman.104.1440746760.11709.python-list@python.org>
In reply to#95726
On Fri, 2015-08-28 at 06:35 +0000, Nick Sarbicki wrote:
> Well who would we fight if we were all friends with each other?

That's what Paintball is for.

/Martin S
-- 
This address is for technical mail lists only.For all other matters, please use my main addressat the .org domain.

[toc] | [prev] | [next] | [standalone]


#95729 — Re: OFF-TOPIC Ben's sig monster quote [was Re: Parametrized Unit Tests]

FromBen Finney <ben+python@benfinney.id.au>
Date2015-08-28 17:27 +1000
SubjectRe: OFF-TOPIC Ben's sig monster quote [was Re: Parametrized Unit Tests]
Message-ID<mailman.105.1440747066.11709.python-list@python.org>
In reply to#95726
Steven D'Aprano <steve@pearwood.info> writes:

> With the greatest of respect to Chomsky, I think he is simply wrong
> about Hitler. Hitler actually believed that war was good for the
> national character, and indeed good for the soul, and that long
> periods of peace would enfeeble a nation and make it decadent and
> effete.

I think the beliefs of Adolf Hitler have been interpreted in a great
many ways by many people, and support for many contradictory positions
can be found in his writings and actions.

Hitler certainly made *offers* of peace several times during the Third
Reich. Those may well have been insincere, but he intended at least some
of his own citizens to be convinced by them.

So I interpret Chomsky's meaning as being that any demagogue can, and
all popular despots do, claim they have all manner of virtuous goals;
therefore we must, to understand their intent, ask anyone speaking of
such virtuous goals what exactly is meant by their pleasing words.

Regardless: I have found that aphorism to be overly flippant and
obscure, I will take this as an opportunity to cull it from my database.

> Many people over the ages have thought that if only war was more
> terrible, we would stop making it. Alas, that appears to be false: no
> matter how terrible war is, there is always someone who thinks that it
> is better than peace.

Those who benefit from a continuance of war have tended to exert
significant effort to reduce the awfulness of war for their own,
non-combatant, civilians: either by making war at a greater remove (the
latest iteration being remote-piloted drone attacks), or by ensuring
civilians don't get to see reports of the awfulness of war.

So the mere fact that we continue to make war doesn't argue against the
hypothesis, because war is still not particularly awful to those that
approve and fund it.

Nonetheless, I also disagree with the hypothesis. I disagree on the
ground that the awfulness of war is determined less by some external
“awfulness of war” parameter, but in large part by the activities of
those who plan it and engage in it. They get the war they create.

-- 
 \     “Capitalism is the astounding belief that the most wickedest of |
  `\    men will do the most wickedest of things for the greatest good |
_o__)                               of everyone.” —John Maynard Keynes |
Ben Finney

[toc] | [prev] | [next] | [standalone]


#95732 — Re: OFF-TOPIC Ben's sig monster quote [was Re: Parametrized Unit Tests]

FromMarko Rauhamaa <marko@pacujo.net>
Date2015-08-28 12:24 +0300
SubjectRe: OFF-TOPIC Ben's sig monster quote [was Re: Parametrized Unit Tests]
Message-ID<87lhcvvk99.fsf@elektro.pacujo.net>
In reply to#95729
Ben Finney <ben+python@benfinney.id.au>:

> Steven D'Aprano <steve@pearwood.info> writes:
>> Many people over the ages have thought that if only war was more
>> terrible, we would stop making it. Alas, that appears to be false: no
>> matter how terrible war is, there is always someone who thinks that
>> it is better than peace.
>
> Those who benefit from a continuance of war have tended to exert
> significant effort to reduce the awfulness of war for their own,
> non-combatant, civilians: either by making war at a greater remove
> (the latest iteration being remote-piloted drone attacks), or by
> ensuring civilians don't get to see reports of the awfulness of war.

There are people around us who see no downsides to war, violence and
killing. Many of them must feel terribly frustrated during periods of
peace. That's why it is extremely difficult to put the genie back in the
bottle when the supposed root cause of the war has been removed (see the
IRA, ETA or the Tamil Tigers, for example).

Would you rather be an powerful, armed war hero admired and feared by
your nation or a foresaken unemployed drunkard who rots in jail?

Communities and unscrupulous leaders have regularly put these berserkers
to good use (<URL: https://en.wikipedia.org/wiki/Berserker>). Eastern
Ukraine is a recent example, but the example is by no means isolated. No
general dares to punish a foot soldier that has taken liberties with
civilians.


Marko

[toc] | [prev] | [next] | [standalone]


#95734 — Re: OFF-TOPIC Ben's sig monster quote [was Re: Parametrized Unit Tests]

Fromjmp <jeanmichel@sequans.com>
Date2015-08-28 11:47 +0200
SubjectRe: OFF-TOPIC Ben's sig monster quote [was Re: Parametrized Unit Tests]
Message-ID<mailman.108.1440755236.11709.python-list@python.org>
In reply to#95732
On 08/28/2015 11:24 AM, Marko Rauhamaa wrote:
> Would you rather be an powerful, armed war hero admired and feared by
> your nation or a foresaken unemployed drunkard who rots in jail?
>
> Marko
>

Time to quote the most famous general in the galaxy:

“Ohhh. Great warrior.Wars not make one great.” ;)

JM

[toc] | [prev] | [next] | [standalone]


#95735 — Re: OFF-TOPIC Ben's sig monster quote [was Re: Parametrized Unit Tests]

FromSteven D'Aprano <steve@pearwood.info>
Date2015-08-29 00:02 +1000
SubjectRe: OFF-TOPIC Ben's sig monster quote [was Re: Parametrized Unit Tests]
Message-ID<55e06a0f$0$1642$c3e8da3$5496439d@news.astraweb.com>
In reply to#95726
On Fri, 28 Aug 2015 04:35 pm, Nick Sarbicki wrote:

> Well who would we fight if we were all friends with each other?

According to the Nac Mac Feegle, there's always *someone* to fight. If not
an enemy, there's always your friends, family, inanimate objects, and if
all else fails, yourself.

"Crivens! I kicked meself in ma ain heid!"



-- 
Steven
"Nae King! Nae Quin! Nae Laird! Nae Master! We'll no be fooled again!"

[toc] | [prev] | [next] | [standalone]


#95736 — Re: OFF-TOPIC Ben's sig monster quote [was Re: Parametrized Unit Tests]

FromChris Angelico <rosuav@gmail.com>
Date2015-08-29 01:07 +1000
SubjectRe: OFF-TOPIC Ben's sig monster quote [was Re: Parametrized Unit Tests]
Message-ID<mailman.109.1440774481.11709.python-list@python.org>
In reply to#95735
On Sat, Aug 29, 2015 at 12:02 AM, Steven D'Aprano <steve@pearwood.info> wrote:
> On Fri, 28 Aug 2015 04:35 pm, Nick Sarbicki wrote:
>
>> Well who would we fight if we were all friends with each other?
>
> According to the Nac Mac Feegle, there's always *someone* to fight. If not
> an enemy, there's always your friends, family, inanimate objects, and if
> all else fails, yourself.
>
> "Crivens! I kicked meself in ma ain heid!"

I've heard plenty of times the old "with friends like these" line.
This seems to merit an even stronger version... with a self like this,
who needs friends?

ChrisA

[toc] | [prev] | [next] | [standalone]


#95745 — Re: OFF-TOPIC Ben's sig monster quote [was Re: Parametrized Unit Tests]

FromMichael Torrie <torriem@gmail.com>
Date2015-08-28 14:00 -0600
SubjectRe: OFF-TOPIC Ben's sig monster quote [was Re: Parametrized Unit Tests]
Message-ID<mailman.116.1440792064.11709.python-list@python.org>
In reply to#95726
On 08/28/2015 01:27 AM, Ben Finney wrote:
> -- 
>  \     “Capitalism is the astounding belief that the most wickedest of |
>   `\    men will do the most wickedest of things for the greatest good |
> _o__)                               of everyone.” —John Maynard Keynes |

Now that is an interesting quote, which I'll remember!

[toc] | [prev] | [next] | [standalone]


#95763 — Re: OFF-TOPIC Ben's sig monster quote [was Re: Parametrized Unit Tests]

FromRustom Mody <rustompmody@gmail.com>
Date2015-08-29 21:34 -0700
SubjectRe: OFF-TOPIC Ben's sig monster quote [was Re: Parametrized Unit Tests]
Message-ID<4d70f14a-f9e5-4b1d-b48e-11ad1d8b7f60@googlegroups.com>
In reply to#95726
On Friday, August 28, 2015 at 11:56:53 AM UTC+5:30, Steven D'Aprano wrote:
> Completely off-topic. Stop reading now if you only want to read things about
> Python.
> 
> 
> On Fri, 28 Aug 2015 09:46 am, Ben Finney wrote:
> 
> > \        “Of course, everybody says they're for peace. Hitler was for |
> > `\      peace. Everybody is for peace. The question is: what kind of |
> > _o__)                                peace?” —Noam Chomsky, 1984-05-14 |
> 
> 
> With the greatest of respect to Chomsky, I think he is simply wrong about
> Hitler. Hitler actually believed that war was good for the national
> character, and indeed good for the soul, and that long periods of peace
> would enfeeble a nation and make it decadent and effete. Unlike a lot of
> people who believe the same thing, Hitler actually had experience in war,
> including a medal for bravery and a serious injury due to poison gas.
> 
> Many people over the ages have thought that if only war was more terrible,
> we would stop making it. Alas, that appears to be false: no matter how
> terrible war is, there is always someone who thinks that it is better than
> peace.



If you focus on war then no-war is not an option.

However we could switch focus a bit from war to semantics and hear the
– by humanity timescale – recent (in)famous reference to 'crusade'
made by a well-known mensa-IQ head of state...

And thence to the underlying mythologies

Most every culture/religion  I know has a '2-tier' mythology thus:

Tier 1. Be nice, Be good, Turn the other cheek, Practice Non-Violence and other such
good stuff

Tier 2. When the above doesn't work and push comes to shove, mow the 'other guy'
down and you are doing God's work (or God himself is doing it... depending on
culture)

So then people think these mythologies are a/the problem and
super-wisely remove them from the education of the rising generation.

And then we have new mythologies to replace the old ones -- Superman,
Star-Wars... Hollywood in general which 'betters' the earlier
mythologies by making good/evil more black&white and removing all
question-marks.

Its is an elegant separation of concerns: Blood on the screen, popcorn in the lap

And inbetween these two mythologies are all the war-mongering ones —
martyr, patriot,  son-of-the-soil… hero

I find it amazing how people cant see that «terrorist» from one side
is «freedom-fighter» from the other.

To see the consequences that the semantics of our words have,
consider this thought-experiment:

«X» is holed-up in town T and authorities need to get him out

Replace «X» by 'murderer' and  bombing out the whole of T to get him
looks implausible, unthinkable

Replace «X» by 'terrorist' and its suddenly routine

Long-story short:

The enunciation "terrorist" is as much an act of terror as the acts of the
"terrorist"

Or

Rambo.desugared() == murderer == OBL.desugared()

[Making that equation more relevant to context and correspondingly polit 
incorrect is left as an exercise to the reader]

Those who wish to abjure war may consider re/de-educating their children
on this matter

रुसि [For GG to please not mess my unicode]

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web