Merge pull request #1960 from nicoddemus/skip-module-level-doc
Add a note about pytest.skip not being allowed at module level
This commit is contained in:
		
						commit
						b071fdc633
					
				| 
						 | 
					@ -293,6 +293,20 @@ imperatively, in test or setup code::
 | 
				
			||||||
            # or
 | 
					            # or
 | 
				
			||||||
            pytest.skip("unsupported configuration")
 | 
					            pytest.skip("unsupported configuration")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Note that calling ``pytest.skip`` at the module level 
 | 
				
			||||||
 | 
					is not allowed since pytest 3.0. If you are upgrading
 | 
				
			||||||
 | 
					and ``pytest.skip`` was being used at the module level, you can set a
 | 
				
			||||||
 | 
					``pytestmark`` variable:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					.. code-block:: python
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    # before pytest 3.0
 | 
				
			||||||
 | 
					    pytest.skip('skipping all tests because of reasons')
 | 
				
			||||||
 | 
					    # after pytest 3.0
 | 
				
			||||||
 | 
					    pytestmark = pytest.mark.skip('skipping all tests because of reasons')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					``pytestmark`` applies a mark or list of marks to all tests in a module.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Skipping on a missing import dependency
 | 
					Skipping on a missing import dependency
 | 
				
			||||||
--------------------------------------------------
 | 
					--------------------------------------------------
 | 
				
			||||||
| 
						 | 
					@ -371,3 +385,27 @@ The equivalent with "boolean conditions" is::
 | 
				
			||||||
    imported before pytest's argument parsing takes place.  For example,
 | 
					    imported before pytest's argument parsing takes place.  For example,
 | 
				
			||||||
    ``conftest.py`` files are imported before command line parsing and thus
 | 
					    ``conftest.py`` files are imported before command line parsing and thus
 | 
				
			||||||
    ``config.getvalue()`` will not execute correctly.
 | 
					    ``config.getvalue()`` will not execute correctly.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Summary
 | 
				
			||||||
 | 
					-------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Here's a quick guide on how to skip tests in a module in different situations:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					1. Skip all tests in a module unconditionally:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  .. code-block:: python
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        pytestmark = pytest.mark.skip('all tests still WIP')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					2. Skip all tests in a module based on some condition:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  .. code-block:: python
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        pytestmark = pytest.mark.skipif(sys.platform == 'win32', 'tests for linux only')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					3. Skip all tests in a module if some import is missing:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  .. code-block:: python
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        pexpect = pytest.importorskip('pexpect')
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue