[py-svn] r57835 - in py/extradoc/talk/pycon-uk-2008: . example ui
hpk at codespeak.net
hpk at codespeak.net
Fri Sep 5 12:08:48 CEST 2008
Author: hpk
Date: Fri Sep 5 12:08:46 2008
New Revision: 57835
Added:
py/extradoc/talk/pycon-uk-2008/example/
py/extradoc/talk/pycon-uk-2008/example/readme.txt (contents, props changed)
py/extradoc/talk/pycon-uk-2008/example/test_doc.txt (contents, props changed)
py/extradoc/talk/pycon-uk-2008/proposal-pytest.txt
- copied unchanged from r57702, py/extradoc/talk/pycon-uk-2008/pytest.txt
py/extradoc/talk/pycon-uk-2008/pytest.txt
- copied, changed from r57702, py/extradoc/talk/ep2008/pytest.txt
py/extradoc/talk/pycon-uk-2008/ui/
- copied from r57702, py/extradoc/talk/ep2008/ui/
Log:
snapshot pycon slides
Added: py/extradoc/talk/pycon-uk-2008/example/readme.txt
==============================================================================
--- (empty file)
+++ py/extradoc/talk/pycon-uk-2008/example/readme.txt Fri Sep 5 12:08:46 2008
@@ -0,0 +1,6 @@
+
+the examples here only work with the 0.9.2 release
+for py/trunk and the upcoming 1.0 release please
+see http://codespeak.net/svn/py/trunk/contrib
+and subscribe to http://codespeak.net/mailman/listinfo/py-dev
+for more info.
Added: py/extradoc/talk/pycon-uk-2008/example/test_doc.txt
==============================================================================
--- (empty file)
+++ py/extradoc/talk/pycon-uk-2008/example/test_doc.txt Fri Sep 5 12:08:46 2008
@@ -0,0 +1,6 @@
+
+this is an example doc test for the py.test tutorial
+
+>>> x = 3
+>>> print x
+3
Copied: py/extradoc/talk/pycon-uk-2008/pytest.txt (from r57702, py/extradoc/talk/ep2008/pytest.txt)
==============================================================================
--- py/extradoc/talk/ep2008/pytest.txt (original)
+++ py/extradoc/talk/pycon-uk-2008/pytest.txt Fri Sep 5 12:08:46 2008
@@ -5,16 +5,27 @@
=================================================================
:author: Holger Krekel, merlinux GmbH
-:event: 7.7.2008, EuroPython 2008, Vilnius
+:event: 13.9.2008, Pycon UK 2008, Birmingham
+
+my background
+===============
+
+- programming since 20 years
+- Python since around 2000
+- released projects: pypy, py lib, rlcompleter2
+- other: mailwitness, shpy, zope work, vadm, codespeak, ...
+- merlinux GmbH since 2004, EU-project 2004-2007
+
What is py.test?
===================
-- **external** testing tool
+- **cross-project** testing tool
- automatically collects and executes tests
- **minimal boilerplate** approach
- **per-project customization**
- many mature features
+- works on linux, windows, osx, python2.3-2.5
Structure of Tutorial (I)
==========================
@@ -35,51 +46,43 @@
- conftest.py mechanism
- test collection hooks
- test running hooks
- - existing extensions
+ - existing extensions: control collection, ReST tests, HTML
+ generation, run prolog tests, run javascript tests
First: Install py.test
============================
install "py.test" (see http://pylib.org):
- - via "easy_install py"
+ - via "easy_install -U py"
- via download and "python setup.py install"
- via svn and adding py/bin to system $PATH
+ - works on python 2.3-2.6, windows, linux, osx
-
-Write and run a first test
+Write and run basic tests
===================================
-let's write a "test_ospath1.py"::
-
- import os.path, py
-
- def test_abspath():
- assert os.path.abspath("/a/b/c") == "/a/b/c"
- p = "a/b"
- cur = os.path.join(os.getcwd(), "a/b")
- assert os.path.abspath("a/b/c") == "/a/b/c"
-
- def test_typeerror():
- assert py.test.raises(TypeError, "os.path.abspath()")
- XXX check why "os.path.abspath(3)" cannot display source lines correctly
-
-then issue on the command line: ``py.test test_ospath1.py``
+example from ``py/path/local/testing/test_local.py``::
+ def test_pypkgdir():
+ datadir = py.test.ensuretemp("pypkgdir")
+ pkg = datadir.ensure('pkg1', dir=1)
+ pkg.ensure("__init__.py")
+ pkg.ensure("subdir/__init__.py")
+ assert pkg.pypkgpath() == pkg
+ assert pkg.join('subdir', '__init__.py').pypkgpath() == pkg
Putting tests in Test Classes
==================================
-test_ospath2.py (one test failing)::
+example from ``py/path/local/testing/test_local.py``::
- import os.path
- class TestOSPath:
- def test_absolute(self):
- assert os.path.abspath("/a/b/c") == "/a/b/c"
- def test_relative(self):
- p = "a/b"
- cur = os.path.join(os.getcwd(), "a/b")
- assert os.path.abspath("a/b/c") == cur
-
+ class TestExecutionOnWindows(LocalSetup):
+ disabled = py.std.sys.platform != 'win32'
+
+ def test_sysfind(self):
+ x = py.path.local.sysfind('cmd')
+ assert x.check(file=1)
+ assert py.path.local.sysfind('jaksdkasldqwe') is None
observations and notes
========================
@@ -87,27 +90,21 @@
- py.test automatically collects ``test_*`` functions
- use ``py.test --collectonly`` to inspect collection
- you can write tests at module global level
-- no need to subclass from py.test
+- no need to subclass "TestCases" like in unittest
- assertion failures provide detailed info
+
Generative / Parametrized tests
=================================
-test_ospath3.py::
+creating three tests with "yield"::
- class TestOSPath:
- def test_gen_absolute(self):
- def checkabssame(p1):
- print "checking on", repr(p1)
- assert os.path.abspath(p1) == p1
- for s in "/ /a /a/b c".split():
- yield checkabssame, s
-
- def test_gen_relative(self):
- for p in "a a/b".split():
- p = "a/b"
- expected = os.path.join(os.getcwd(), p)
- yield lambda x,y: x==y, p, expected
+ def check(x):
+ assert x >= 0
+
+ def test_gen():
+ for x in 1,2,3:
+ yield check, x
Useful Features
@@ -135,34 +132,24 @@
Setup and Teardown of test state
==================================
-hooks at module, class, instance level, example::
-
- import py, os.path
+let's revisit the above ``test_local.py``:
- def setup_module(mod):
- mod.tmpdir = py.test.ensuretemp(__name__)
+ class LocalSetup:
+ def setup_class(cls):
+ cls.root = py.test.ensuretemp(cls.__name__)
+ cls.root.ensure(dir=1)
+ setuptestfs(cls.root)
- class TestOS:
def setup_method(self, method):
- self.tmpdir = tmpdir.mkdir(method.__name__)
- print "chdir() to ", self.tmpdir
- self.oldcwd = self.tmpdir.chdir()
- def teardown_method(self, method):
- self.oldcwd.chdir()
-
- def test_relative(self):
- p = "a/b"
- expected = os.path.join(str(self.tmpdir), p)
- assert os.path.abspath(p) == expected + "xxx"
+ self.tmpdir = self.root.mkdir(method.__name__)
Skipping tests
===================
-the above tests do not make sense for win32,
-you can insert e.g.::
+Sometimes you need to skip test, use ``py.test.skip``::
- class TestOSPosix:
+ class TestSomeClass:
def setup_class(cls):
if sys.platform == "win32":
py.test.skip("posix platform required")
@@ -173,7 +160,7 @@
Doctests
=================
-py.test automatically collects test_doc.txt files::
+py.test automatically collects ``test_doc.txt`` files::
this is an example doc test for the py.test tutorial
@@ -190,8 +177,7 @@
- integrate new test "items" or "collectors"
- add command line options
- influence the collection process
-- conftest.py's are picked up "upwards"
-- to aid debugging use::
+- for debugging::
py.test --collectonly
py.test --traceconfig
@@ -229,7 +215,7 @@
**dynamic lookup of Collector/Item class from conftest.py files**
-Example conftest.py: control traversal
+Example conftest.py: control directory traversal
===================================================
a conftest.py to influence collection::
@@ -237,16 +223,15 @@
import py
mydir = py.magic.autopath().dirpath()
class Directory(py.test.collect.Directory):
- def run(self):
- if self.fspath == mydir:
- return ["x", "y", "z"]
- return super(Directory, self).run()
-
+ def recfilter(self, path):
+ if path.dirpath() == mydir:
+ return path.basename in ('x', 'y', 'z')
+ return super(Directory, self).recfilter(path)
Example conftest.py: add ReST check support
==============================================
-look into py/doc/conftest.py:
+look into ``py/doc/conftest.py``:
- this produces non-python test items
- ``py.test --collectonly`` shows the custom tree
@@ -317,39 +302,39 @@
- you can extend and modify the collection process
- you can add new (non-python) test items
- conftest.py files are usually "drop in" plugins
+- often project independent
+- **orthogonality** of conftest features
-note, however:
-
-- no easy customization of reporting (yet)
-- details will change for py lib 1.0 release, thus
- if you use special conftest's be sure to subscribe
- http://codespeak.net/mailman/listinfo/py-dev
-
-
-XXX refactor / do extra slides see what could stay / below
-
-
-
-
-
-
-
-
-
-
-
-
+but note:
+- customization gets easier with the upcoming 1.0 release,
+ please subscribe to http://codespeak.net/mailman/listinfo/py-dev
recap: main features
======================
-- assertions by assert statement, nice debugging
+- assertions by assert statement
+- informative concise debugging messages
- unittests, generative tests, doctests, rest-tests
- automatic customize collection of tests
- select tests by keyword
- capture stdout/stderr per-test
+Summary / questions
+==========================
+
+- minimal boilerplate
+- re-use assert statement
+- easy to customize for your test suites
+- use existing and evolving features for your project!
+
+links:
+
+http://pylib.org http://pytest.org
+http://merlinux.eu - holger at merlinux.de
+https://codespeak.net/svn/py/extradoc/talk/ep2008/pytest.txt
+
+
ad-hoc distribution of tests
===================================
@@ -373,10 +358,6 @@
- expects plain Python executable on remote side
- no need to pre-install other software remotely
-- generated AJAX application async displays test results
-
-- demo
-
cross-platform testing
=============================
More information about the pytest-commit
mailing list