Giter Club home page Giter Club logo

pytest-pudb's Introduction

pytest-pudb

Travis-ci: continuous integration status.

Pytest PuDB debugger integration based on pytest PDB integration

Use it as --pdb py.test command argument:

py.test --pudb

Or simply use pudb.set_trace inside your python code:

def test_set_trace_integration():
    # No --capture=no need
    import pudb
    pudb.set_trace()
    assert 1 == 2

def test_pudb_b_integration():
    # No --capture=no need
    import pudb.b
    # traceback is set up here
    assert 1 == 2

See also pytest and pudb projects.

pytest-pudb's People

Contributors

noirbizarre avatar wilfred avatar wronglink avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

pytest-pudb's Issues

Look at __tracebackhide__

Functions like numpy.testing.assert_equal add __tracebackhide__ = True to their locals to make pytest ignore them in the traceback reporting. The --pudb flag should automatically jump up to the first frame that doesn't have __tracebackhide__, so that it starts on the same frame that is shown in the test failure traceback.

Latest Pytest release (3.3.1) breaks pytest-pudb

Simply because of this method renaming in Pytest's CaptureManager plugin: suspendcapture -> suspend_global_capture. Using the new name works (so far).

Apparently the fix could also make this work with pre-3.3.1 version of Pytest. (try use the new name, otherwise use the old name).

PyPI package for v0.4 is broken

Earlier today, HISTORY.rst was added to the repo and version 0.4 was published to PyPI. HISTORY.rst is not included in published source package, leading to this error or similar during install:

    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/private/var/folders/vr/swfrp8952bxbpzk3fx3b1fyh0000gn/T/pip-build-gsinvzjt/pytest-pudb/setup.py", line 11, in <module>
        open('HISTORY.rst').read(),
    FileNotFoundError: [Errno 2] No such file or directory: 'HISTORY.rst'

tagging releases

Hi there,

I'm working on a debian package for this pytest plugin. It would be super useful to have tags in the git repo for releases since the tags could be used by tools that automatically lookup new versions.
There are releases on pypi, but those don't contain the unit tests which are important to run during package building to make sure that the code is expected to work properly. So for the debian packaging it's more useful to grab archives for tags from github.

would you be willing to create tags at least for the current latest release and add them for future releases too?

Cheers!

pytest-pudb breaks datetime

I can reproduce the error in my machine. But some of my collegues don't get the same behaviour.

with the following test file (/tmp/test_datetime.py):

def test_strptime():
    import datetime
    datetime.datetime.strptime('29-April-2013', "%d-%B-%Y")

then :

✔ /tmp 
19:08 $ conda create -n test pytest
Fetching package metadata .........
Solving package specifications: .

Package plan for installation in environment /home/sik/miniconda3/envs/test:

The following NEW packages will be INSTALLED:

    openssl:    1.0.2l-0     
    pip:        9.0.1-py36_1 
    py:         1.4.34-py36_0
    pytest:     3.1.3-py36_0 
    python:     3.6.2-0      
    readline:   6.2-2        
    setuptools: 27.2.0-py36_0
    sqlite:     3.13.0-0     
    tk:         8.5.18-0     
    wheel:      0.29.0-py36_0
    xz:         5.2.2-1      
    zlib:       1.2.8-3      

Proceed ([y]/n)? y

#
# To activate this environment, use:
# > source activate test
#
# To deactivate an active environment, use:
# > source deactivate
#

✔ /tmp 
19:08 $ source activate test
(test) ✔ /tmp 
19:08 $ pytest test_datetime.py 
=================================== test session starts ===================================
platform linux -- Python 3.6.2, pytest-3.1.3, py-1.4.34, pluggy-0.4.0
rootdir: /tmp, inifile:
collected 1 item s

test_datetime.py .

================================ 1 passed in 0.01 seconds =================================
(test) ✔ /tmp 
19:09 $ pip install pytest-pudb
Collecting pytest-pudb
Collecting pudb (from pytest-pudb)
Requirement already satisfied: pytest>=2.0 in /home/sik/miniconda3/envs/test/lib/python3.6/site-packages (from pytest-pudb)
Collecting pygments>=1.0 (from pudb->pytest-pudb)
  Using cached Pygments-2.2.0-py2.py3-none-any.whl
Collecting urwid>=1.1.1 (from pudb->pytest-pudb)
Requirement already satisfied: py>=1.4.33 in /home/sik/miniconda3/envs/test/lib/python3.6/site-packages (from pytest>=2.0->pytest-pudb)
Requirement already satisfied: setuptools in /home/sik/miniconda3/envs/test/lib/python3.6/site-packages/setuptools-27.2.0-py3.6.egg (from pytest>=2.0->pytest-pudb)
Installing collected packages: pygments, urwid, pudb, pytest-pudb
Successfully installed pudb-2017.1.2 pygments-2.2.0 pytest-pudb-0.5 urwid-1.3.1
(test) ✔ /tmp 
19:09 $ pytest test_datetime.py 
=================================== test session starts ===================================
platform linux -- Python 3.6.2, pytest-3.1.3, py-1.4.34, pluggy-0.4.0
rootdir: /tmp, inifile:
plugins: pudb-0.5
collected 1 item s

test_datetime.py F

======================================== FAILURES =========================================
______________________________________ test_strptime ______________________________________

    def test_strptime():
        import datetime
>       datetime.datetime.strptime('29-April-2013', "%d-%B-%Y")

test_datetime.py:3: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/home/sik/miniconda3/envs/test/lib/python3.6/_strptime.py:565: in _strptime_datetime
    tt, fraction = _strptime(data_string, format)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

data_string = '29-April-2013', format = '%d-%B-%Y'

    def _strptime(data_string, format="%a %b %d %H:%M:%S %Y"):
        """Return a 2-tuple consisting of a time struct and an int containing
        the number of microseconds based on the input string and the
        format string."""
    
        for index, arg in enumerate([data_string, format]):
            if not isinstance(arg, str):
                msg = "strptime() argument {} must be str, not {}"
                raise TypeError(msg.format(index, type(arg)))
    
        global _TimeRE_cache, _regex_cache
        with _cache_lock:
            locale_time = _TimeRE_cache.locale_time
            if (_getlang() != locale_time.lang or
                time.tzname != locale_time.tzname or
                time.daylight != locale_time.daylight):
                _TimeRE_cache = TimeRE()
                _regex_cache.clear()
                locale_time = _TimeRE_cache.locale_time
            if len(_regex_cache) > _CACHE_MAX_SIZE:
                _regex_cache.clear()
            format_regex = _regex_cache.get(format)
            if not format_regex:
                try:
                    format_regex = _TimeRE_cache.compile(format)
                # KeyError raised when a bad format is found; can be specified as
                # \\, in which case it was a stray % but with a space after it
                except KeyError as err:
                    bad_directive = err.args[0]
                    if bad_directive == "\\":
                        bad_directive = "%"
                    del err
                    raise ValueError("'%s' is a bad directive in format '%s'" %
                                        (bad_directive, format)) from None
                # IndexError only occurs when the format string is "%"
                except IndexError:
                    raise ValueError("stray %% in format '%s'" % format) from None
                _regex_cache[format] = format_regex
        found = format_regex.match(data_string)
        if not found:
            raise ValueError("time data %r does not match format %r" %
>                            (data_string, format))
E           ValueError: time data '29-April-2013' does not match format '%d-%B-%Y'

/home/sik/miniconda3/envs/test/lib/python3.6/_strptime.py:362: ValueError
================================ 1 failed in 0.07 seconds =================================

TypeError in PuDBInvoke when using pytest --capture=no

PuDBInvoke failes when an exception's raised in tests when pytest's run with --capture=no, pytest_pudb.py::PuDBInvoke raises:

Traceback (most recent call last):
  File ".../.virtualenvs/.../lib/python3.4/site-packages/_pytest/main.py", line 178, in wrap_session
    session.exitstatus = doit(config, session) or 0
  File ".../.virtualenvs/.../lib/python3.4/site-packages/_pytest/main.py", line 215, in _main
    config.hook.pytest_runtestloop(session=session)
  File ".../.virtualenvs/.../lib/python3.4/site-packages/pluggy/hooks.py", line 258, in __call__
    return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
  File ".../.virtualenvs/.../lib/python3.4/site-packages/pluggy/manager.py", line 67, in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
  File ".../.virtualenvs/.../lib/python3.4/site-packages/pluggy/manager.py", line 61, in <lambda>
    firstresult=hook.spec_opts.get('firstresult'),
  File ".../.virtualenvs/.../lib/python3.4/site-packages/pluggy/callers.py", line 201, in _multicall
    return outcome.get_result()
  File ".../.virtualenvs/.../lib/python3.4/site-packages/pluggy/callers.py", line 76, in get_result
    raise ex[1].with_traceback(ex[2])
  File ".../.virtualenvs/.../lib/python3.4/site-packages/pluggy/callers.py", line 180, in _multicall
    res = hook_impl.function(*args)
  File ".../.virtualenvs/.../lib/python3.4/site-packages/_pytest/main.py", line 236, in pytest_runtestloop
    item.config.hook.pytest_runtest_protocol(item=item, nextitem=nextitem)
  File ".../.virtualenvs/.../lib/python3.4/site-packages/pluggy/hooks.py", line 258, in __call__
    return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
  File ".../.virtualenvs/.../lib/python3.4/site-packages/pluggy/manager.py", line 67, in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
  File ".../.virtualenvs/.../lib/python3.4/site-packages/pluggy/manager.py", line 61, in <lambda>
    firstresult=hook.spec_opts.get('firstresult'),
  File ".../.virtualenvs/.../lib/python3.4/site-packages/pluggy/callers.py", line 201, in _multicall
    return outcome.get_result()
  File ".../.virtualenvs/.../lib/python3.4/site-packages/pluggy/callers.py", line 76, in get_result
    raise ex[1].with_traceback(ex[2])
  File ".../.virtualenvs/.../lib/python3.4/site-packages/pluggy/callers.py", line 180, in _multicall
    res = hook_impl.function(*args)
  File ".../.virtualenvs/.../lib/python3.4/site-packages/_pytest/runner.py", line 66, in pytest_runtest_protocol
    runtestprotocol(item, nextitem=nextitem)
  File ".../.virtualenvs/.../lib/python3.4/site-packages/_pytest/runner.py", line 81, in runtestprotocol
    reports.append(call_and_report(item, "call", log))
  File ".../.virtualenvs/.../lib/python3.4/site-packages/_pytest/runner.py", line 167, in call_and_report
    hook.pytest_exception_interact(node=item, call=call, report=report)
  File ".../.virtualenvs/.../lib/python3.4/site-packages/pluggy/hooks.py", line 258, in __call__
    return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
  File ".../.virtualenvs/.../lib/python3.4/site-packages/pluggy/manager.py", line 67, in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
  File ".../.virtualenvs/.../lib/python3.4/site-packages/pluggy/manager.py", line 61, in <lambda>
    firstresult=hook.spec_opts.get('firstresult'),
  File ".../.virtualenvs/.../lib/python3.4/site-packages/pluggy/callers.py", line 201, in _multicall
    return outcome.get_result()
  File ".../.virtualenvs/.../lib/python3.4/site-packages/pluggy/callers.py", line 76, in get_result
    raise ex[1].with_traceback(ex[2])
  File ".../.virtualenvs/.../lib/python3.4/site-packages/pluggy/callers.py", line 180, in _multicall
    res = hook_impl.function(*args)
  File ".../.virtualenvs/.../lib/python3.4/site-packages/pytest_pudb.py", line 69, in pytest_exception_interact
    out, err = _suspend_capture(capman, in_=True)
TypeError: 'NoneType' object is not iterable

I'm using:

pytest==3.7.4
pytest-pudb==0.6

I've not time to properly look at this, but I'm seeing this:

  1. Test/fixture raises ...
  2. PuDBInvoke calls _suspend_capture ...
  3. _suspend_capture's calling suspend_global_capture, which always returns None.
  4. None's split into (out, err), raising the above.

My local workaround's below, but this doesn't fix the real issue within PuDBInvoke and _suspend_capture:

*** pytest_pudb.py.orig	Thu Sep  6 05:25:27 2018
--- pytest_pudb.py	Thu Sep  6 04:38:33 2018
*************** class PuDBInvoke(object):
*** 66,74 ****
      def pytest_exception_interact(self, node, call, report):
          capman = node.config.pluginmanager.getplugin("capturemanager")
          if capman:
!             out, err = _suspend_capture(capman, in_=True)
!             sys.stdout.write(out)
!             sys.stdout.write(err)
          _enter_pudb(node, call.excinfo, report)
  
      def pytest_internalerror(self, excrepr, excinfo):
--- 66,76 ----
      def pytest_exception_interact(self, node, call, report):
          capman = node.config.pluginmanager.getplugin("capturemanager")
          if capman:
!             capture_streams = _suspend_capture(capman, in_=True)
!             if capture_streams:
!                 out, err = capture_streams
!                 sys.stdout.write(out)
!                 sys.stdout.write(err)
          _enter_pudb(node, call.excinfo, report)
  
      def pytest_internalerror(self, excrepr, excinfo):

Support pu.db

pu.db

is a shorter work-alike of

import pudb;pudb.set_trace()

which could be supported.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.