[py-svn] r65880 - py/extradoc/talk/ep2009/pytest-advanced

hpk at codespeak.net hpk at codespeak.net
Tue Jun 23 13:17:27 CEST 2009


Author: hpk
Date: Tue Jun 23 13:17:26 2009
New Revision: 65880

Added:
   py/extradoc/talk/ep2009/pytest-advanced/   (props changed)
      - copied from r65320, py/extradoc/talk/pycon-us-2009/pytest-advanced/
Modified:
   py/extradoc/talk/ep2009/pytest-advanced/author.latex
   py/extradoc/talk/ep2009/pytest-advanced/pytest-advanced.txt
Log:
working on ep 2009 slides ... 


Modified: py/extradoc/talk/ep2009/pytest-advanced/author.latex
==============================================================================
--- py/extradoc/talk/pycon-us-2009/pytest-advanced/author.latex	(original)
+++ py/extradoc/talk/ep2009/pytest-advanced/author.latex	Tue Jun 23 13:17:26 2009
@@ -1,7 +1,7 @@
 \definecolor{rrblitbackground}{rgb}{0.0, 0.0, 0.0}
 
-\title[pytest advanced testing tutorial] {pytest advanced testing tutorial}
+\title[rapid testing with py.test] {rapid testing with py.test}
 \author[H. Krekel]{Holger Krekel \\ http://merlinux.eu}
 
-\institute[Pycon US 2009, Chicago]{Pycon US 2009, Chicago}
-\date{March 26, 2009}
+\institute[EuroPython 2009, Birmingham]{EuroPython 2009, Birmingham}
+\date{June 29, 2009}

Modified: py/extradoc/talk/ep2009/pytest-advanced/pytest-advanced.txt
==============================================================================
--- py/extradoc/talk/pycon-us-2009/pytest-advanced/pytest-advanced.txt	(original)
+++ py/extradoc/talk/ep2009/pytest-advanced/pytest-advanced.txt	Tue Jun 23 13:17:26 2009
@@ -2,19 +2,19 @@
 .. include:: <s5defs.txt>
 
 =================================================================
-Advanced cross platform testing 
+Rapid testing with py.test 
 =================================================================
 
-If you have time, please install 
+Install
 ========================================
 
 - svn checkout http://codespeak.net/svn/py/dist 
+- hg clone https://hpk42@bitbucket.org/hpk42/py-trunk/
 
 - run "python setup.py" with "install" or "develop"
 
 - if need be: easy_install "py" 
 
-- slides: http://tinyurl.com/c76gve
 
 my technical background 
 ===========================
@@ -26,15 +26,6 @@
 - merlinux GmbH since 2004
 - PyPy EU-project 2004-2007 
 
-my current background 
-========================
-
-.. image:: img/little_red_riding_hood_by_marikaz.jpg
-   :scale: 100
-   :align: left
- 
-http://marikaz.deviantart.com/ CC 3.0 AN-ND
-
 my testing background 
 =======================
 
@@ -42,7 +33,7 @@
 - "test-driven developer" (TDD) since 2002 
 - founded PyPy, based on TDD principles 
 - developed utest/stdtest, now py.test 
-- consulted to help with testing 
+- consultancies on testing 
 
 What's **your** background? 
 ==============================
@@ -171,7 +162,7 @@
 merge with real-life deployment. 
 
 
-pytest advanced features (30 minutes) 
+Walkthrough Python test functions (30 minutes) 
 ============================================================================
 
 .. image:: img/new_color_in_dark_old_city_by_marikaz.jpg
@@ -180,7 +171,44 @@
 
 http://marikaz.deviantart.com/  CC 3.0 AN-ND
 
-Python test function viewed abstractly 
+A Typical Python test layout 
+==========================================
+::
+
+    app/__init__.py   
+    ...
+    app/tests/test_module.py 
+    ...
+
+py.test invocation: ``py.test app`` 
+
+Another typical test layout 
+==========================================
+::
+
+    app/__init__.py   
+    tests/test_module.py 
+
+py.test invocation: ``py.test tests``. 
+
+Mind the the `__init__.py` files! 
+==========================================
+
+wherever your "tests" directories are, 
+always provide a ``__init__.py``
+
+automatic test discovery 
+===================================
+
+py.test walks over your source tree and: 
+
+- discovers ``test_*.py`` test files 
+- discovers ``test_`` functions or ``Test`` classes
+
+**automatic discovery avoids boilerplate**
+
+
+Typical test function - viewed abstractly 
 ==========================================
 ::
 
@@ -190,14 +218,18 @@
         ...
         assert "things are ok"
    
-observations
+observations and the setup question 
 ==========================================
 
-* test configuration mixes with code instantiation
+* test values / configuration mixes with test code 
 * importing 'app' may fail 
-* the "app.pkg.SomeClass" reference may change 
+* the ``app.pkg.SomeClass`` reference may change 
+
+what if multiple test functions setup the same
+classes, maybe with slightly different values? 
+
 
-setting up state close to code
+x-unit style setup / fixtures
 ==========================================
 
 ::
@@ -214,61 +246,72 @@
 observations 
 ==========================================
 
-* test configuration mixes with code instantiation
+* test values / configuration mixes with test code 
 * importing 'app' may fail 
-* the "app.pkg.SomeClass" reference may change 
-* **functions tend to group by setup methods**
+* the ``app.pkg.SomeClass`` reference may change 
+* **functions now group by setup/fixture code**
 * **multiple methods can reuse the same setup**
 
-meet py.test "funcargs" 
+meet "funcargs" - test function arguments 
 ==========================================
 
-goals: 
+::
 
-* fully separate test setup from test code 
-* setup app bootstraps in one place 
-* allow to group tests in classes or files logically 
+ def test_something(inst1):
+   assert inst1.call() == "result" 
 
-basic funcarg mechanism 
+observations 
 ==========================================
 
-- have a test function specify its needed setup
-- lookup and call a function that provides setup 
+* test values are simply used in test code 
+* no imports or app.pkg.SomeClass references here 
+* freedom to group tests logically 
+* multiple functions can re-use the same funcarg setup
 
-Example test function
+How to setup the funcarg value? 
 ==========================================
-::
+:: 
+    
+ from app.pkg import SomeClass 
+ def pytest_funcarg__inst1(request):
+   return SomeClass("somevalue") 
 
- def test_somefunction(myarg):
-   assert myarg == 'test_somefunction'
+defined in: test module, ``conftest.py`` or named plugin 
 
-Example conftest.py 
-==========================================
-:: 
+observations
+===================================================
 
- class ConftestPlugin:
-   def pytest_funcarg__myarg(self, pyfuncitem):
-     return pyfuncitem.name 
+* funcarg provider automatically discovered 
+* app bootstraps for testing in one place 
+* funcarg can be used from different test functions
+
+introducing a command line option 
+===================================================
+:: 
+ # ./tests/conftest.py 
+ def pytest_addoption(parser):
+   parser.addoption("--val", action="store")
+ def pytest_funcarg_inst1(request):
+   return SomeClass(request.config.getvalue("val"))
 
 observations
-=====================
+===================================================
 
-funcargs:
+* test configuration separated from test code 
+* app bootstraps for testing in one place 
+* can be used from any test function anywhere 
 
-* test functions receive value by specifying a name
-* makers are registered after command line parsing 
-* makers have meta-access to "collected function item" 
+``request`` object attributes
+===================================================
 
-notes on "named based lookup" 
-===================================
+``request.function``: python test function 
 
-py.test often looks up names:
+``request.cls``: containing test class 
 
-- discover ``test_*.py`` test files 
-- discover ``test_`` functions or ``Test`` classes
-- and now: discover test function arguments 
+``request.module``: test module 
+
+``request.config``: access to options and general config 
 
-**automatic discovery avoids boilerplate**
 
 Exercise 
 ==========================================



More information about the pytest-commit mailing list