[py-dev] branch is being merged back
Hi all, we are currently merging back the py-collect branch [1]. Although this is a huge diff we don't expect big problems unless you are using "conftest.py" customizations. There are a couple of new command line options, most notably Jan Balster's "--tkinter" frontend. It's at an early experimental stage but already starts to be usable. Note that the command line options changed slightly, because there is a new rule: py.test will consume all lowercase single-letter options like "-h", "-v", "-x" and so on while applications should add only consume capital cased letters. One major change that took place in the branch is that we are refraining from import magic for importing test modules. This deprives us of the ability to run tests directly from a remote repository, but allows to get rid of some nasty interactions with e.g. nevow's import hacks. have fun and report any problems, holger [1] Jan, if you have a locally modified pycollect branch you will have to switch to the dist directory because the branch/py-collect is no more and you can't commit to it ...
On 2005.04.16 21:57:51 +0000, holger krekel wrote:
Note that the command line options changed slightly, because there is a new rule: py.test will consume all lowercase single-letter options like "-h", "-v", "-x" and so on while applications should add only consume capital cased letters.
Haven't looked at the new code yet, so maybe I'm interpreting your statement incorrectly, but this seems wrong. I currently don't rely on the value of sys.argv in unit tests. If I need to test a script that uses argv, I split out a main function from the top-level "if __name__ == '__main__'" block and make the latter as small and simple as possible (usually just "main()") so I don't have to test it. Then I do: def main(argv=sys.argv) or sometimes even: def main(argv=None): if argv is None: argv = sys.argv So that I have the ability to plug in different argv values for testing, without actually hacking the "real" sys.argv This is occasionally inconvenient. For example, sometimes a script requires a password, and you don't want to hardcode it, and you don't want to put it in a file, and you don't want your test to be overly interactive, and putting it on the command line feels like the least insecure of the simple options. (I know, someone could use ps to sniff it, so this is hardly super-secure.) Now, it would be nice to assume that py.test will leave {some of} sys.argv alone, so that I have the option of using it. But a rule based on capitalization seems like the wrong way to do this. I want to pick option names for my programs based on what's user-friendly, not what my test framework allows. Maybe a better way to do this would be some kind of --the-rest-go-to-the-program-under-test option (with a shorter name), that py.test could use to split sys.argv. py.test would consume anything on the command line before the marker, and pass everything after it to the application as sys.argv -- David Ripton dripton@ripton.net
Hi David, On Mon, Apr 18, 2005 at 06:52 -0700, David Ripton wrote:
On 2005.04.16 21:57:51 +0000, holger krekel wrote:
Note that the command line options changed slightly, because there is a new rule: py.test will consume all lowercase single-letter options like "-h", "-v", "-x" and so on while applications should add only consume capital cased letters.
Haven't looked at the new code yet, so maybe I'm interpreting your statement incorrectly, but this seems wrong.
Sorry, i wasn't very precise in my above statement. py.test has always been using command line options. But, for example with PyPy, we have a couple of extra options to the testing process (which you can provide through 'conftest.py' files in your package). Now the idea is that such test extensions (what i called "applications" above) should use upper-case letters while py.test restrains itself to only use lower-case ones. This way py.test has enough future possible options :-) So with respect to what a test module finds in sys.argv nothing has changed. In fact, if a test module inspects sys.argv it will find the complete list of options (provided to py.test).
I currently don't rely on the value of sys.argv in unit tests. If I need to test a script that uses argv, I split out a main function from the top-level "if __name__ == '__main__'" block and make the latter as small and simple as possible (usually just "main()") so I don't have to test it.
makes sense.
... This is occasionally inconvenient. For example, sometimes a script requires a password, and you don't want to hardcode it, and you don't want to put it in a file, and you don't want your test to be overly interactive, and putting it on the command line feels like the least insecure of the simple options. (I know, someone could use ps to sniff it, so this is hardly super-secure.)
Now, it would be nice to assume that py.test will leave {some of} sys.argv alone, so that I have the option of using it.
Yes, although it is not completely obvious how to exactly do it (also with respect to the underlying optparse-usage).
But a rule based on capitalization seems like the wrong way to do this. I want to pick option names for my programs based on what's user-friendly, not what my test framework allows.
Sure but py.test is usually not running your application, is it? :-) Basically i would suggest that you add a special testing command line option that holds your password information. E.g. in a conftest.py in your package you could add: option = py.test.addptions("my app testing options", Option('-P', '--password', action="store", default=None, type="string", dest="password", help="password used for XXX connections."), And then in your test_whatever.py: from mypackage.conftest import option .... def test_something(): myscript.main(...use option.password... ) If you then are in your package and issue 'py.test -h' it will have your option. cheers, holger
participants (3)
-
David Ripton -
holger krekel -
hpk@trillke.net