[py-svn] r65935 - in py/extradoc/talk/ep2009: pytest-advanced rapid-testing

hpk at codespeak.net hpk at codespeak.net
Wed Jun 24 21:25:54 CEST 2009


Author: hpk
Date: Wed Jun 24 21:25:54 2009
New Revision: 65935

Added:
   py/extradoc/talk/ep2009/rapid-testing/
      - copied from r65880, py/extradoc/talk/ep2009/pytest-advanced/
   py/extradoc/talk/ep2009/rapid-testing/makepdf
      - copied, changed from r65909, py/extradoc/talk/ep2009/pytest-advanced/makepdf
   py/extradoc/talk/ep2009/rapid-testing/rapid-testing.txt   (props changed)
      - copied unchanged from r65880, py/extradoc/talk/ep2009/pytest-advanced/pytest-advanced.txt
   py/extradoc/talk/ep2009/rapid-testing/test_addfinalizer.py
      - copied unchanged from r65909, py/extradoc/talk/ep2009/pytest-advanced/test_addfinalizer.py
   py/extradoc/talk/ep2009/rapid-testing/test_cached_setup.py
      - copied unchanged from r65909, py/extradoc/talk/ep2009/pytest-advanced/test_cached_setup.py
   py/extradoc/talk/ep2009/rapid-testing/test_generate_tests.py
      - copied unchanged from r65909, py/extradoc/talk/ep2009/pytest-advanced/test_generate_tests.py
Removed:
   py/extradoc/talk/ep2009/pytest-advanced/
   py/extradoc/talk/ep2009/rapid-testing/pytest-advanced.pdf
   py/extradoc/talk/ep2009/rapid-testing/pytest-advanced.txt
Log:
rename to rapid-testing


Copied: py/extradoc/talk/ep2009/rapid-testing/makepdf (from r65909, py/extradoc/talk/ep2009/pytest-advanced/makepdf)
==============================================================================
--- py/extradoc/talk/ep2009/pytest-advanced/makepdf	(original)
+++ py/extradoc/talk/ep2009/rapid-testing/makepdf	Wed Jun 24 21:25:54 2009
@@ -6,7 +6,7 @@
 # WARNING: to work, it needs this patch for docutils
 # https://sourceforge.net/tracker/?func=detail&atid=422032&aid=1459707&group_id=38414
 
-BASE=pytest-advanced
+BASE=rapid-testing
 python rst2beamer.py --stylesheet=stylesheet.latex --documentoptions=13pt $BASE.txt $BASE.latex || exit
 sed 's/\\date{}/\\input{author.latex}/' $BASE.latex >tmpfile || exit
 sed 's/\\maketitle/\\input{title.latex}/' tmpfile >$BASE.latex || exit

Deleted: /py/extradoc/talk/ep2009/pytest-advanced/pytest-advanced.pdf
==============================================================================
Files /py/extradoc/talk/ep2009/pytest-advanced/pytest-advanced.pdf	Wed Jun 24 21:25:54 2009 and (empty file) differ

Deleted: /py/extradoc/talk/ep2009/pytest-advanced/pytest-advanced.txt
==============================================================================
--- /py/extradoc/talk/ep2009/pytest-advanced/pytest-advanced.txt	Wed Jun 24 21:25:54 2009
+++ (empty file)
@@ -1,691 +0,0 @@
-.. include:: beamerdefs.txt
-.. include:: <s5defs.txt>
-
-=================================================================
-Rapid testing with py.test 
-=================================================================
-
-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" 
-
-
-my technical background 
-===========================
-
-- programming since 20 years
-- Python since around 2000 
-- released projects: pypy, py.test/py lib, rlcompleter2
-- other: mailwitness, shpy, vadm, codespeak, ... 
-- merlinux GmbH since 2004
-- PyPy EU-project 2004-2007 
-
-my testing background 
-=======================
-
-- learned Python 2001 
-- "test-driven developer" (TDD) since 2002 
-- founded PyPy, based on TDD principles 
-- developed utest/stdtest, now py.test 
-- consultancies on testing 
-
-What's **your** background? 
-==============================
-
-- what test tools do you use? 
-- work test-driven? 
-- have test-suites with >1000 tests? 
-- need/want to run tests on >1 platforms? 
-- have "non-python" tests? 
-
-Python 
-==================================
-
-Python has no compile-time type security. 
-
-
-Testing to the rescue! 
-==================================
-
-automated tests are better than declaring types. 
-
-The test tool question
-========================================
-
-what is the job of automated testing tools? 
-
-my current answer
-========================================
-
-* verify that my code changes work out 
-* be helpful when test scenarios fail
-
-If failures are not helpful ...
-========================================
-
-improve the test tool or 
-
-write more (different) tests
-
-The Automated Test question
-========================================
-
-what are automated tests there for? 
-
-my current answer
-========================================
-
-to make sure that
-
-* units react well to input. 
-* components co-operate nicely 
-* code changes work out in the end
-
-What does "code changes work out" mean? 
-========================================
-
-.. image:: img/rails_in_the_city_by_marikaz.jpg
-   :scale: 90
-   :align: center
-
-http://marikaz.deviantart.com/  CC 3.0 AN-ND
-
-my current answer 
-========================================
-
-- various operating systems
-- various Python Interpreters
-- cloud environments
-- web browsers etc. 
-
-Common Test terminology
-==============================
-
-- developer and customer tests
-- unit tests 
-- functional tests
-- acceptance tests 
-- integration tests 
-
-you may discuss a long time 
-about categorizations ...
-
-py.test strives to test it all 
-=================================
-
-current focus: 
-
-- unittesting
-- functional
-- integration tests 
-
-A pragmatic view on test types
-=================================
-
-let's talk about small, medium or large tests. 
-
-Small Tests: one aspect
-==============================
-
-.. image:: img/small.png
-   :align: center
-   :scale: 70
-
-Medium Tests: two aspects 
-==============================
-
-.. image:: img/medium.png
-   :align: center
-   :scale: 70
-
-Large Tests: end-to-end
-==============================
-
-.. image:: img/large.png
-   :align: center
-   :scale: 70
-
-generally speaking
-============================================
-
-what is the vision of automated testing? 
-
-my current answer 
-========================================
-
-merge with real-life deployment. 
-
-
-Walkthrough Python test functions (30 minutes) 
-============================================================================
-
-.. image:: img/new_color_in_dark_old_city_by_marikaz.jpg
-   :scale: 100
-   :align: left
-
-http://marikaz.deviantart.com/  CC 3.0 AN-ND
-
-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 
-==========================================
-::
-
-    from app.pkg import SomeClass 
-    def test_something():
-        inst1 = SomeClass("somevalue") 
-        ...
-        assert "things are ok"
-   
-observations and the setup question 
-==========================================
-
-* test values / configuration mixes with test code 
-* importing 'app' may fail 
-* the ``app.pkg.SomeClass`` reference may change 
-
-what if multiple test functions setup the same
-classes, maybe with slightly different values? 
-
-
-x-unit style setup / fixtures
-==========================================
-
-::
-
-    from app.pkg import SomeClass 
-    class TestGroup:
-        def setup_method(self, method):
-            self.inst1 = SomeClass("somevalue")  
-           
-        def test_something(self):
-            ... use self.inst1 ...  
-            assert "things are ok"
-
-observations 
-==========================================
-
-* test values / configuration mixes with test code 
-* importing 'app' may fail 
-* the ``app.pkg.SomeClass`` reference may change 
-* **functions now group by setup/fixture code**
-* **multiple methods can reuse the same setup**
-
-meet "funcargs" - test function arguments 
-==========================================
-
-::
-
- def test_something(inst1):
-   assert inst1.call() == "result" 
-
-observations 
-==========================================
-
-* 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
-
-How to setup the funcarg value? 
-==========================================
-:: 
-    
- from app.pkg import SomeClass 
- def pytest_funcarg__inst1(request):
-   return SomeClass("somevalue") 
-
-defined in: test module, ``conftest.py`` or named plugin 
-
-observations
-===================================================
-
-* 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
-===================================================
-
-* test configuration separated from test code 
-* app bootstraps for testing in one place 
-* can be used from any test function anywhere 
-
-``request`` object attributes
-===================================================
-
-``request.function``: python test function 
-
-``request.cls``: containing test class 
-
-``request.module``: test module 
-
-``request.config``: access to options and general config 
-
-
-Exercise 
-==========================================
-
-* write a new package "mypkg"
-* add mypkg/__init__ and mypkg/test_url.py 
-* add a test_path function that needs an "url" argument 
-* write the provider in mypkg/conftest.py 
-* run your test 
-
-Bonus: add more tests, play with wrongly named args. 
-
-Using Plugins and Extensions 
-=========================================
-
-.. image:: img/end_of_a_age_by_marikaz.jpg
-   :scale: 100
-   :align: left
-
-http://marikaz.deviantart.com/  CC 3.0 AN-ND
-
-Historic view 
-==========================
-
-- 0.9.x uses conftest's for extension and configuration
-- 1.0 uses "plugins" for extending and conftest.py for configuration 
-- we do "smooth" transition because of existing test code base 
-
-Customizing py.test 
-===========================
-
-- configuration values go to conftest.py files 
-- write local or global plugins 
-- provide funcargs 
-
-Conftest.py
-===============
-
-- can be put into test directory or higher up 
-- contains test configuration values 
-- specifies plugins to use 
-- can provide default values for command line options 
-
-Specifying plugins 
-========================
-
-- ``-p NAME``: load comma-separated list of plugins 
-- plugins are always named "pytest_NAME" and can be 
-  anywhere in your import path 
-
-Writing a local conftest plugin
-====================================
-
-you can write a local conftest.py based plugin::
-
-    class ConftestPlugin:
-        def pytest_addoption(self, parser):
-            parser.addoption("--myworld", action="store_true")
-        ...
-
-Exercise
-==========================================
-
-* add an option for specifying url on the command line 
-* look at "py.test -h"
-
-
-other Plugin Examples
-=========================================
-
-- integrate collection/run of traditional unit-tests
-- run functions in their own tempdir 
-- testing ReST documents
-- running Prolog tests (old: conftest based)
-- running Javascript tests (old: conftest based) 
-- html reporting for nightly runs (old: conftest-based) 
-
-if time permits ... 
-=========================================
-
-- let's play with "pytest_unittest" plugin
-
-Break 
-=====
-
-.. image:: img/flying_lady_by_marikaz.jpg
-   :scale: 100
-   :align: left
-
-http://marikaz.deviantart.com/  CC 3.0 AN-ND
-
-
-Writing Plugins (30 minutes)
-============================================================================
-
-- test collection objects 
-- plugin hooks and events 
-- event system for custom reporting 
-- test collection hooks 
-- test running hooks 
-
-py.test collection objects
-=============================
-
-* collectors, ``collect()`` returns list of "colitems"
-* items, implement ``runtest()`` for running a test 
-
-test collection tree 
-========================
-
-- collection tree is built iteratively
-- test collection starts from directories or files (via cmdline)
-
-py.test.collect.* filesystem objects 
-======================================
-
-- **Directory** 
-- **File** 
-
-always available Attributes 
-=======================================
-
-**parent** a reference to the collector that produced us
-
-**name**: a name that is unique within the scope of our parent
-
-**config**:  test configuration
-
-Python object collectors 
-=======================================
-
-**obj** points to the underlying python object. 
-
-- **Module** 
-- **Class**/**Instance** 
-- **Generator** 
-- **Function** 
-
-Exercise "collection tree"
-====================================
-
-inspecting the test collection tree::
-
-    py.test --collectonly 
-
-Hooks and Events 
-===================
-
-- Plugin hook methods implement interaction 
-  with configuration/collection/running of tests 
-
-- Events are called for notification purposes, 
-  are not asked for return values. 
-
-Configuration Hooks
-======================
-::
-
- def pytest_addoption(self, parser):
-    """ called before commandline parsing.  """
-
- def pytest_configure(self, config):
-    """ called after command line options have been parsed. "
-
- def pytest_unconfigure(self, config):
-    """ called before test process is exited. """
-
-Collection Hooks
-======================
-::
-
- def pytest_collect_file(self, path, parent):
-    """ return Collection node or None. """
-
- def pytest_collect_directory(self, path, parent):
-    """ return Collection node or None. """
-
- def pytest_collect_recurse(self, path, parent):
-    """ return True/False to cause/prevent recursion. """
-
-Python collection hooks 
-=====================================
-::
- def pytest_pymodule_makeitem(self, modcol, name, obj):
-     """ return custom item/collector for a python object in a module, or None.  """
-
-function test run hooks 
-==========================
-::
-    def pytest_pyfunc_call(self, pyfuncitem, args, kwargs):
-        """ return True if we consumed/did the call to the python function item. """
-
-    def pytest_item_makereport(self, item, excinfo, when, outerr):
-        """ return ItemTestReport event for the given test outcome. """
-
-Reporting hooks 
-==========================
-::
-    def pytest_report_teststatus(self, event):
-        """ return shortletter and verbose word. """
-
-    def pytest_terminal_summary(self, terminalreporter):
-        """ add additional section in terminal summary reporting. """
-
-Event methods
-===============
-
-are only called, no interaction. 
-
-see ``py/test/plugin/pytest_terminal.py``
-for a full selection of events. 
-
-Warning 
-===============
-
-naming changes might take place before 1.0 final 
-
-Writing cross-project plugins
-==================================
-
-- put plugin into pytest_name.py or package
-- make a "NamePlugin" class available 
-- release or copy to somewhere importable 
-
-Exercise 
-==================================
-
-* port conftest plugin to global "pytest_myapp" plugin. 
-* put pytest_myapp somewhere where it's importable (or release it :) 
-* put "pytest_plugins = 'pytest_myapp'" into your test module 
-
-
-Distributed Testing (45 minutes)
-====================================
-
-.. image:: img/rails_in_the_city_by_marikaz.jpg 
-   :scale: 100
-   :align: left
-
-http://marikaz.deviantart.com/  CC 3.0 AN-ND
-
-
-the basic idea 
-====================================
-
-collect tests locally, 
-run tests in separated test execution processes. 
-
-test distribution modes 
-====================================
-
---dist=load  # load-balance tests to exec environments 
---dist=each  # send each test to each exec environment 
-
-send test to one other python interpreter
-==================================================
-
-::
-
-    py.test --dist=each --tx popen//python=python2.4
-
-send test to three different interpreters 
-==================================================
-
-::
-
-    py.test --dist=each \
-        --tx=popen//python=python2.4 \
-        --tx=popen//python=python2.5 \
-        --tx=popen//python=python2.6 
-
-Example: Speed up test runs 
-====================================
-
-To send tests to multiple CPUs, type::
-
-    py.test --dist=load --tx popen --tx popen --tx popen 
-
-or in short::
-
-    py.test -n 3 
-
-Especially for longer running tests or tests requiring 
-a lot of IO this can lead to considerable speed ups! 
-
-send tests to remote SSH accout 
-========================================
-
-::
-
-    py.test --d --tx ssh=myhostpopen --rsyncdir mypkg mypkg
-
-Sending tests to remote socket servers
-========================================
-
-Download and start 
-
-http://codespeak.net/svn/py/dist/py/execnet/script/socketserver.py
-
-Assuming an IP address, you can now tell py.test to distribute: :
-
-    py.test -d --tx socket=192.168.1.102:8888 --rsyncdir mypkg mypkg
-
-Exercise: Move settings into conftest
-========================================
-
-mypkg/conftest.py::
-    rsyncdirs = ['.']
-    pytest_option_tx = ['ssh=myhost', 'socket=...']
-
-mypkg/conftest.py::
-    rsyncdirs = ['.']
-
-Distribution modes 
-========================================
-
-:: 
-
-    py.test --dist=each mypkg 
-
-    py.test --dist=load mypkg 
-
-how does py.test do all this? 
-========================================
-
-it uses py.execnet! 
-
-``py.execnet``
-========================================
-
-* instantiates local or remote Python Processes
-* send code for execution in one or many processes 
-* asynchronously send and receive data between processes through channels 
-* completely avoid manual installation steps on remote places
-
-xspecs: Exec environment specs 
-================================= 
-
-general form::
-
-    key1=value1//key2=value2//key3=value3
-
-xspec key meanings 
-================================= 
-
-* ``popen`` for a PopenGateway
-* ``ssh=host`` for a SshGateway
-* ``socket=address:port`` for a SocketGateway 
-* ``python=executable`` for specifying Python executables
-* ``chdir=path`` change remote working dir to given relative or absolute path
-* ``nice=value`` decrease remote nice level if platforms supports it 
-
-xspec examples 
-================================= 
-
-::
-    ssh=wyvern//python=python2.4//chdir=mycache
-    popen//python=2.5//nice=20
-    socket=192.168.1.4:8888
-
-Exercise
-================================= 
-
-* Play with runing your tests in multiple interpreters or processes 
-* see if you can get access to your neighbour's PC 
-   
-
-Feedback round 
-==================
-
-How did you like the tutorial? 
-
-Thanks for taking part! 
-
-holger krekel at merlinux eu 
-
- 



More information about the pytest-commit mailing list