Skip to content

Instantly share code, notes, and snippets.

View nicoddemus's full-sized avatar

Bruno Oliveira nicoddemus

View GitHub Profile
@nicoddemus
nicoddemus / kw.py
Last active November 7, 2015 21:31
Handling keyword arguments default values
# python 2
def foo(**kwargs):
x = kwargs.pop('x', 10)
y = kwargs.pop('y', 'no value')
if kwargs:
raise TypeError('unknown keyword arguments: %s' % kwargs.keys())
print x, y
@nicoddemus
nicoddemus / warnings.py
Created November 26, 2015 17:42
warnings snippets
# Code typically replaced by _warnings
def warn(message, category=None, stacklevel=1):
"""Issue a warning, or maybe ignore it or raise an exception."""
# Check if message is already a Warning object
if isinstance(message, Warning):
category = message.__class__
# Check category argument
if category is None:
category = UserWarning
if not (isinstance(category, type) and issubclass(category, Warning)):
@nicoddemus
nicoddemus / 2.9.0.rst
Last active December 22, 2015 22:19
pytest changelog sample

2.9.0.dev

  • New pytest.mark.skip mark, which unconditional skips marked tests. Thanks `@MichaelAquilina`_ for the complete PR (`#1040`_).
  • Fix `#680`_: the -s and -c options should now work under xdist; Config.fromdictargs now represents its input much more faithfully. Thanks to `@bukzor`_ for the complete PR.
@nicoddemus
nicoddemus / get-reqs.py
Created January 4, 2016 11:20
get requirements from current conda env
from __future__ import unicode_literals
from __future__ import print_function
import json
import subprocess
libs = json.loads(subprocess.check_output('conda list -e --json', shell=True))
lines = []
for name in libs:
@nicoddemus
nicoddemus / test_server.py
Created July 7, 2016 20:08
FTPServer fixture example
import re
from pyftpdlib.authorizers import DummyAuthorizer
from pyftpdlib.handlers import FTPHandler
from pyftpdlib.servers import FTPServer
import pytest
@pytest.yield_fixture
def ftp_server(tmpdir, request):
authorizer = DummyAuthorizer()
@nicoddemus
nicoddemus / bld.bat
Last active July 8, 2016 12:33
pytest-2.9.1 recipe
"%PYTHON%" setup.py install
if errorlevel 1 exit 1
:: Add more build steps here, if they are necessary.
:: See
:: http://docs.continuum.io/conda/build.html
:: for a list of environment variables that are set during the build process.
from __future__ import absolute_import, division, print_function, unicode_literals
from functools import partial
class Hooks:
def pytest_about_to_timeout(self, config):
pass
=========================== pytest-warning summary ============================
WW0 in testing\acceptance_test.py:629 the following warning was recorded:
..\..\..\..\..\..\..\..\..\pytest\.tox\py35\lib\site-packages\_pytest\vendored_packages\pluggy.py:250: PendingDeprecationWarning: generator 'pytest_pycollect_makeitem' raised StopIteration
wrap_controller.send(call_outcome)
WW0 in testing\deprecated_test.py:62 the following warning was recorded:
.tox\py35\lib\site-packages\_pytest\recwarn.py:65: DeprecationWarning: use of getfuncargvalue is deprecated, use getfixturevalue
old_warn(message, category, *args, **kwargs)
WW0 in testing\test_collection.py:350 the following warning was recorded:
@nicoddemus
nicoddemus / generate_tests_tree.py
Created November 22, 2016 12:44
Generates dummy test tree
"""
Creates a dummy tree with test files, with or without conftest.py files.
Usage:
generate_tests_tree.py 4 6 10 0
Generates a tree 4 levels deep, 6 folders per level and 10 test files each, without any conftest.py files. Each
test file contains 10 dummy tests.
"""
$ unzip -l library.zip
Archive: library.zip
Length Date Time Name
--------- ---------- ----- ----
0 2016-11-30 08:21 funcsigs/
0 2016-11-30 08:21 funcsigs-1.0.2.dist-info/
13297 2016-11-30 08:21 funcsigs-1.0.2.dist-info/DESCRIPTION.rst
4 2016-11-30 08:21 funcsigs-1.0.2.dist-info/INSTALLER
14420 2016-11-30 08:21 funcsigs-1.0.2.dist-info/METADATA
1294 2016-11-30 08:21 funcsigs-1.0.2.dist-info/metadata.json