Hamcrest matchers for Python

Related tags

TestingPyHamcrest
Overview

PyHamcrest

Introduction

PyHamcrest is a framework for writing matcher objects, allowing you to declaratively define "match" rules. There are a number of situations where matchers are invaluable, such as UI validation, or data filtering, but it is in the area of writing flexible tests that matchers are most commonly used. This tutorial shows you how to use PyHamcrest for unit testing.

When writing tests it is sometimes difficult to get the balance right between overspecifying the test (and making it brittle to changes), and not specifying enough (making the test less valuable since it continues to pass even when the thing being tested is broken). Having a tool that allows you to pick out precisely the aspect under test and describe the values it should have, to a controlled level of precision, helps greatly in writing tests that are "just right." Such tests fail when the behavior of the aspect under test deviates from the expected behavior, yet continue to pass when minor, unrelated changes to the behaviour are made.

Installation

Hamcrest can be installed using the usual Python packaging tools. It depends on distribute, but as long as you have a network connection when you install, the installation process will take care of that for you.

My first PyHamcrest test

We'll start by writing a very simple PyUnit test, but instead of using PyUnit's assertEqual method, we'll use PyHamcrest's assert_that construct and the standard set of matchers:

from hamcrest import *
import unittest


class BiscuitTest(unittest.TestCase):
    def testEquals(self):
        theBiscuit = Biscuit("Ginger")
        myBiscuit = Biscuit("Ginger")
        assert_that(theBiscuit, equal_to(myBiscuit))


if __name__ == "__main__":
    unittest.main()

The assert_that function is a stylized sentence for making a test assertion. In this example, the subject of the assertion is the object theBiscuit, which is the first method parameter. The second method parameter is a matcher for Biscuit objects, here a matcher that checks one object is equal to another using the Python == operator. The test passes since the Biscuit class defines an __eq__ method.

If you have more than one assertion in your test you can include an identifier for the tested value in the assertion:

assert_that(theBiscuit.getChocolateChipCount(), equal_to(10), "chocolate chips")
assert_that(theBiscuit.getHazelnutCount(), equal_to(3), "hazelnuts")

As a convenience, assert_that can also be used to verify a boolean condition:

assert_that(theBiscuit.isCooked(), "cooked")

This is equivalent to the assert_ method of unittest.TestCase, but because it's a standalone function, it offers greater flexibility in test writing.

Predefined matchers

PyHamcrest comes with a library of useful matchers:

  • Object
    • equal_to - match equal object
    • has_length - match len()
    • has_property - match value of property with given name
    • has_properties - match an object that has all of the given properties.
    • has_string - match str()
    • instance_of - match object type
    • none, not_none - match None, or not None
    • same_instance - match same object
    • calling, raises - wrap a method call and assert that it raises an exception
  • Number
    • close_to - match number close to a given value
    • greater_than, greater_than_or_equal_to, less_than, less_than_or_equal_to - match numeric ordering
  • Text
    • contains_string - match part of a string
    • ends_with - match the end of a string
    • equal_to_ignoring_case - match the complete string but ignore case
    • equal_to_ignoring_whitespace - match the complete string but ignore extra whitespace
    • matches_regexp - match a regular expression in a string
    • starts_with - match the beginning of a string
    • string_contains_in_order - match parts of a string, in relative order
  • Logical
    • all_of - and together all matchers
    • any_of - or together all matchers
    • anything - match anything, useful in composite matchers when you don't care about a particular value
    • is_not, not_ - negate the matcher
  • Sequence
    • contains - exactly match the entire sequence
    • contains_inanyorder - match the entire sequence, but in any order
    • has_item - match if given item appears in the sequence
    • has_items - match if all given items appear in the sequence, in any order
    • is_in - match if item appears in the given sequence
    • only_contains - match if sequence's items appear in given list
    • empty - match if the sequence is empty
  • Dictionary
    • has_entries - match dictionary with list of key-value pairs
    • has_entry - match dictionary containing a key-value pair
    • has_key - match dictionary with a key
    • has_value - match dictionary with a value
  • Decorator
    • calling - wrap a callable in a deferred object, for subsequent matching on calling behaviour
    • raises - Ensure that a deferred callable raises as expected
    • described_as - give the matcher a custom failure description
    • is_ - decorator to improve readability - see Syntactic sugar below

The arguments for many of these matchers accept not just a matching value, but another matcher, so matchers can be composed for greater flexibility. For example, only_contains(less_than(5)) will match any sequence where every item is less than 5.

Syntactic sugar

PyHamcrest strives to make your tests as readable as possible. For example, the is_ matcher is a wrapper that doesn't add any extra behavior to the underlying matcher. The following assertions are all equivalent:

assert_that(theBiscuit, equal_to(myBiscuit))
assert_that(theBiscuit, is_(equal_to(myBiscuit)))
assert_that(theBiscuit, is_(myBiscuit))

The last form is allowed since is_(value) wraps most non-matcher arguments with equal_to. But if the argument is a type, it is wrapped with instance_of, so the following are also equivalent:

assert_that(theBiscuit, instance_of(Biscuit))
assert_that(theBiscuit, is_(instance_of(Biscuit)))
assert_that(theBiscuit, is_(Biscuit))

Note that PyHamcrest's ``is_`` matcher is unrelated to Python's ``is`` operator. The matcher for object identity is ``same_instance``.

Writing custom matchers

PyHamcrest comes bundled with lots of useful matchers, but you'll probably find that you need to create your own from time to time to fit your testing needs. This commonly occurs when you find a fragment of code that tests the same set of properties over and over again (and in different tests), and you want to bundle the fragment into a single assertion. By writing your own matcher you'll eliminate code duplication and make your tests more readable!

Let's write our own matcher for testing if a calendar date falls on a Saturday. This is the test we want to write:

def testDateIsOnASaturday(self):
    d = datetime.date(2008, 4, 26)
    assert_that(d, is_(on_a_saturday()))

And here's the implementation:

from hamcrest.core.base_matcher import BaseMatcher
from hamcrest.core.helpers.hasmethod import hasmethod


class IsGivenDayOfWeek(BaseMatcher):
    def __init__(self, day):
        self.day = day  # Monday is 0, Sunday is 6

    def _matches(self, item):
        if not hasmethod(item, "weekday"):
            return False
        return item.weekday() == self.day

    def describe_to(self, description):
        day_as_string = [
            "Monday",
            "Tuesday",
            "Wednesday",
            "Thursday",
            "Friday",
            "Saturday",
            "Sunday",
        ]
        description.append_text("calendar date falling on ").append_text(
            day_as_string[self.day]
        )


def on_a_saturday():
    return IsGivenDayOfWeek(5)

For our Matcher implementation we implement the _matches method - which calls the weekday method after confirming that the argument (which may not be a date) has such a method - and the describe_to method - which is used to produce a failure message when a test fails. Here's an example of how the failure message looks:

assert_that(datetime.date(2008, 4, 6), is_(on_a_saturday()))

fails with the message:

AssertionError:
Expected: is calendar date falling on Saturday
     got: <2008-04-06>

Let's say this matcher is saved in a module named isgivendayofweek. We could use it in our test by importing the factory function on_a_saturday:

from hamcrest import *
import unittest
from isgivendayofweek import on_a_saturday


class DateTest(unittest.TestCase):
    def testDateIsOnASaturday(self):
        d = datetime.date(2008, 4, 26)
        assert_that(d, is_(on_a_saturday()))


if __name__ == "__main__":
    unittest.main()

Even though the on_a_saturday function creates a new matcher each time it is called, you should not assume this is the only usage pattern for your matcher. Therefore you should make sure your matcher is stateless, so a single instance can be reused between matches.

More resources

Comments
  • PyHamcrest 1.10.0 is not py2-compatible. It should set python_requires>=3 to avoid breaking users who are still on Py2.

    PyHamcrest 1.10.0 is not py2-compatible. It should set python_requires>=3 to avoid breaking users who are still on Py2.

    import hamcrest no longer works on Python 2 with pyhamcrest==1.10.0.

    To avoid installation of pyhamcrest==1.10.0 and newer versions on Python 2, it would be better to add python_requires>=3.0 stanza in setup.py starting from 1.10.0. To fix this for 1.10.0, we would need to update already released 1.10.0 pypi artifacts.

    As of now, all python 2 users who install pyhamcrest without restricting the version to 1.9.0, will be broken.

    A better user experience would be if Python 2 users get the last version of pyhamcrest that is supported on Python 2. This is convention is often followed by major python libraries, for example numpy.

    opened by tvalentyn 16
  • Created calling/raises matcher

    Created calling/raises matcher

    New functional implementation of assert raises that uses the matcher style of hamcrest to check that exceptions are being raised as expected with the new matcher raises. There is a helper called calling that wraps a call with arguments to delay execution to where the matcher can catch any raised exception, but you can happily use raises on any function that takes no arguments. As a bonus, you can provide a regex to raises and it will look for that pattern in the stringification of the assertion - important in cases where a verification stage may throw variations of the same assertion.

    Accepts any subclass of the exception provided. Does not try to run uncallable actuals.

    assert_that(calling(parse, bad_data), raises(ValueError))
    assert_that(calling(translate).with_(curse_words), raises(LanguageError, "\w+very naughty"))
    assert_that(broken, raises(Exception))
    # This will fail and complain that 23 is not callable
    # assert_that(23, raises(IOError))
    
    opened by perfa 16
  • The test suite fails with pytest 4

    The test suite fails with pytest 4

    While packaging PyHamcrest for openSUSE/Tumbledweed, I have discovered that the test suite fails with Pytest 4.

    [   34s] + PYTHONPATH=:/home/abuild/rpmbuild/BUILDROOT/python-PyHamcrest-1.9.0-0.x86_64/usr/lib/python2.7/site-packages
    [   34s] + py.test-2.7 --ignore=_build.python2 --ignore=_build.python3 --ignore=_build.pypy3 -v
    [   34s] ============================= test session starts ==============================
    [   34s] platform linux2 -- Python 2.7.16, pytest-4.6.5, py-1.8.0, pluggy-0.13.0 -- /usr/bin/python2
    [   34s] cachedir: .pytest_cache
    [   34s] hypothesis profile 'default' -> database=DirectoryBasedExampleDatabase('/home/abuild/rpmbuild/BUILD/PyHamcrest-1.9.0/.hypothesis/examples')
    [   34s] rootdir: /home/abuild/rpmbuild/BUILD/PyHamcrest-1.9.0
    [   34s] plugins: hypothesis-4.40.2
    [   36s] collecting ... collected 453 items / 2 errors / 451 selected
    [   36s] 
    [   36s] ==================================== ERRORS ====================================
    [   36s] __________ ERROR collecting tests/hamcrest_unit_test/core/is_test.py ___________
    [   36s] /usr/lib/python2.7/site-packages/pluggy/hooks.py:286: in __call__
    [   36s]     return self._hookexec(self, self.get_hookimpls(), kwargs)
    [   36s] /usr/lib/python2.7/site-packages/pluggy/manager.py:92: in _hookexec
    [   36s]     return self._inner_hookexec(hook, methods, kwargs)
    [   36s] /usr/lib/python2.7/site-packages/pluggy/manager.py:86: in <lambda>
    [   36s]     firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
    [   36s] /usr/lib/python2.7/site-packages/_pytest/python.py:234: in pytest_pycollect_makeitem
    [   36s]     res = list(collector._genfunctions(name, obj))
    [   36s] /usr/lib/python2.7/site-packages/_pytest/python.py:410: in _genfunctions
    [   36s]     self.ihook.pytest_generate_tests(metafunc=metafunc)
    [   36s] /usr/lib/python2.7/site-packages/pluggy/hooks.py:286: in __call__
    [   36s]     return self._hookexec(self, self.get_hookimpls(), kwargs)
    [   36s] /usr/lib/python2.7/site-packages/pluggy/manager.py:92: in _hookexec
    [   36s]     return self._inner_hookexec(hook, methods, kwargs)
    [   36s] /usr/lib/python2.7/site-packages/pluggy/manager.py:86: in <lambda>
    [   36s]     firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
    [   36s] /usr/lib/python2.7/site-packages/_pytest/python.py:137: in pytest_generate_tests
    [   36s]     metafunc.parametrize(*marker.args, **marker.kwargs)
    [   36s] /usr/lib/python2.7/site-packages/_pytest/python.py:1004: in parametrize
    [   36s]     function_definition=self.definition,
    [   36s] /usr/lib/python2.7/site-packages/_pytest/mark/structures.py:130: in _for_parametrize
    [   36s]     if len(param.values) != len(argnames):
    [   36s] E   TypeError: object of type 'MarkDecorator' has no len()
    [   36s] _____ ERROR collecting tests/hamcrest_unit_test/core/isinstanceof_test.py ______
    [   36s] /usr/lib/python2.7/site-packages/pluggy/hooks.py:286: in __call__
    [   36s]     return self._hookexec(self, self.get_hookimpls(), kwargs)
    [   36s] /usr/lib/python2.7/site-packages/pluggy/manager.py:92: in _hookexec
    [   36s]     return self._inner_hookexec(hook, methods, kwargs)
    [   36s] /usr/lib/python2.7/site-packages/pluggy/manager.py:86: in <lambda>
    [   36s]     firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
    [   36s] /usr/lib/python2.7/site-packages/_pytest/python.py:234: in pytest_pycollect_makeitem
    [   36s]     res = list(collector._genfunctions(name, obj))
    [   36s] /usr/lib/python2.7/site-packages/_pytest/python.py:410: in _genfunctions
    [   36s]     self.ihook.pytest_generate_tests(metafunc=metafunc)
    [   36s] /usr/lib/python2.7/site-packages/pluggy/hooks.py:286: in __call__
    [   36s]     return self._hookexec(self, self.get_hookimpls(), kwargs)
    [   36s] /usr/lib/python2.7/site-packages/pluggy/manager.py:92: in _hookexec
    [   36s]     return self._inner_hookexec(hook, methods, kwargs)
    [   36s] /usr/lib/python2.7/site-packages/pluggy/manager.py:86: in <lambda>
    [   36s]     firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
    [   36s] /usr/lib/python2.7/site-packages/_pytest/python.py:137: in pytest_generate_tests
    [   36s]     metafunc.parametrize(*marker.args, **marker.kwargs)
    [   36s] /usr/lib/python2.7/site-packages/_pytest/python.py:1004: in parametrize
    [   36s]     function_definition=self.definition,
    [   36s] /usr/lib/python2.7/site-packages/_pytest/mark/structures.py:130: in _for_parametrize
    [   36s]     if len(param.values) != len(argnames):
    [   36s] E   TypeError: object of type 'MarkDecorator' has no len()
    [   36s] !!!!!!!!!!!!!!!!!!! Interrupted: 2 errors during collection !!!!!!!!!!!!!!!!!!!!
    [   36s] =========================== 2 error in 1.48 seconds ============================
    

    The full build log is also available.

    opened by mcepl 15
  • add has_return_value matcher.

    add has_return_value matcher.

    Hello, maintainers of PyHamcrest! Long-time admirer, first time pull-requester.

    This new matcher will match against the return value of an object's method. In the world of web automation, this matcher will be particularly useful to test for things like whether an element is displayed by matching against its is_displayed() method return value, or checking class strings, or any number of things an automated tester might need to check.

    I've already created a version of this matcher locally in a test suite that's using my ScreenPy library, but i think the work i did there would be useful to others in this more generalized form.

    I tried my best to follow the conventions i saw elsewhere in this codebase. Please let me know if i've left something out or am not following the conventions correctly—i am happy to make any changes you might want!

    opened by perrygoy 11
  • Python version compatibility metadata

    Python version compatibility metadata

    This PR adds packaging metadata that marks the package as only supporting Python 3.5+. This prevents Pip from installing it on Python 2.7.

    You can find documentation here: https://setuptools.readthedocs.io/en/latest/setuptools.html#new-and-changed-setup-keywords (search in page for "python_requires").

    I'm not sure how you do releases, but I'll note that you may need non-ancient (last four years or so) setuptools to generate a wheel that contains this metadata.

    Fixes #131.

    opened by twm 11
  • Output of has_properties over verbose

    Output of has_properties over verbose

    I think the mismatch description of has_porperties is very verbose and actually making readability worse.

    assert_that(b, has_properties(x=6))
    Expected: (an object with a property 'x' matching <6>)
         but: an object with a property 'x' matching <6> property 'x' was <7>
    

    this is from all_of repeating the offending matcher, which does make sense when the user composes various matchers. But has_properties to the user is a single matcher and the output is only confusing if you don't know it's made up of multiple matchers.

    opened by keis 11
  • Don't use describe_to of mock objects

    Don't use describe_to of mock objects

    When using hamcrest together with mocks and asserting that the same mock objects are being passed around the assertion messages produce are bad because hamcrest ends up calling describe_to of the mocks which does nothing.

    before

    >>> from hamcrest import assert_that, equal_to
    >>> from unittest.mock import Mock
    >>> a,b = Mock(),Mock()
    >>> assert_that(a, equal_to(b))
    AssertionError: 
    Expected: 
         but: was 
    

    after

    >>> from hamcrest import assert_that, equal_to
    >>> from unittest.mock import Mock
    >>> a,b = Mock(),Mock()
    AssertionError: 
    Expected: <Mock id='139861799912056'>
         but: was <Mock id='139861799911832'>
    
    opened by keis 11
  • Provide better mismatch descriptions for `any_of` and `only_contains`

    Provide better mismatch descriptions for `any_of` and `only_contains`

    What problem does this merge request solve?

    running

    from hamcrest import *
    
    if __name__ == '__main__':
        assert_that(['a'], only_contains(has_length(3)))
    

    in master reports

    Traceback (most recent call last):
    ...
    AssertionError:
    Expected: a sequence containing items matching (an object with length of <3>)
         but: was <['a']>
    

    after the merge request, the error message becomes

    Traceback (most recent call last):
    ...
    AssertionError:
    Expected: a sequence containing items matching (an object with length of <3>)
         but: was <['a']>, first sequence item not matching was 'a' with length of <1>
    

    However, this merge request is not perfect.

    Known (Guessed) Problems

    • if sequence is a stream generator that can only be iterated once, then describe_mismatch will fail trying to iterate it again. I believe it would be safe to encapsulate list(sequence) as an instance variable (or hide behind a memoized property) where it could be used from both methods, but the tutorial/docs are pushing in the direction of stateless matcher preferences. Thus not being familiar enough with the architecture and usages of hamcrest, I didn't want to do that initially

    Potentatial Improvements

    • prefix/postfix could be handled as TestCase class variables (like a "Template Method")
    • any_of had the same problem (8f0bcce) as only_contains (5a6c990) - not having a proper delegation to the actual matchers to provide the mismatch description. I suspect there can be other (composite) matchers that have the same issue.
    • now issequence_onlycontaining_test is coupled to the has_length implementation. Probably there is (should be) a way to have a matcher with test-controllable describe_foo values, so there is no need for coupling. Then the initial assertions from testDescribeMismatchDisplayUsedMatchersDescriptionForFirstFailingItem could be removed
    • there is too much duplication between describe_mismatch and _matches. However, to resolve that by introducing a get_first_mismatch method would need to be an object (can't use None due to the need to distinguish between no mismatches and TypeError return type cases), and I didn't want to invest in that until I knew that change was welcome
    opened by zsoldosp 11
  • is_not/not_ will not invert raises() matcher

    is_not/not_ will not invert raises() matcher

    As far as I can tell is_not should invert any matcher. Recently had a situation where I need an to invert a raises and it did not work as expected. In some ways inverting raises is an antipattern but in my case alternatives are uglier. Below is a simplified example of the issue.

    Please advise if this is a bug? or is there an alternative way to address this.

    Content example.py

    from hamcrest import assert_that, calling, raises, not_                            
    assert_that(calling(int).with_args('q'), not_(raises(ValueError)))
    

    Output:

    Traceback (most recent call last):
      File "/home/test/example1.py", line 2, in <module>
        assert_that(calling(int).with_args('q'), not_(raises(ValueError)))
      File "/home/test/_venv/lib/python3.6/site-packages/hamcrest/core/assert_that.py", line 43, in assert_that
        _assert_match(actual=arg1, matcher=arg2, reason=arg3)
      File "/home/test/_venv/lib/python3.6/site-packages/hamcrest/core/assert_that.py", line 57, in _assert_match
        raise AssertionError(description)
    AssertionError: 
    Expected: not Expected a callable raising <class 'ValueError'>
         but: was <hamcrest.core.core.raises.DeferredCallable object at 0x7ffbaaba97f0>
    

    Expected: test passing

    opened by hersheleh 10
  • Improve has_properties description.

    Improve has_properties description.

    Before:

    str(has_properties(x=6, y=5, z=7))
    (an object with a property 'x' matching <6> and an object with a property 'y' matching <5> and an object with a property 'z' matching <7>)
    

    After:

    str(has_properties(x=6, y=5, z=7))
    an object with properties 'x' matching <6> and 'y' matching <5> and 'z' matching <7>
    
    opened by brunns 10
  • Add `not_` to the matcher-list in the Readme.

    Add `not_` to the matcher-list in the Readme.

    not_ is an alias for is_not which is used for readability reasons. It should be mentioned in the Readme because this is the list where many people look for a list of matchers, especially as long as #74 is not fixed.

    opened by Kaligule 9
  • Matchers should be contravariant

    Matchers should be contravariant

    Currently, the Matcher class has a type arg T as it should, but Matchers are currently invariant with respect to T. However, I think it's quite clear that the following should be legal code:

    matcher: Matcher[str] = has_length(greater_than(0))
    

    I've recreated that definition here:

    from typing import Any, Generic, Sequence, Sized, TypeVar
    
    T = TypeVar("T")
    
    
    class Matcher(Generic[T]):
      def matches(self, _: T) -> bool:
        ...
    
    
    def greater_than(_: Any) -> Matcher[Any]:
      ...
    
    
    def has_length(_: int | Matcher[int]) -> Matcher[Sized]:
      ...
    
    
    matcher: Matcher[str] = has_length(greater_than(0))
    

    Pyright provides the following error:

    » pyright test.py
    [...]
    test.py
      test.py:23:25 - error: Expression of type "Matcher[Sized]" cannot be assigned to declared type "Matcher[str]"
        "Matcher[Sized]" is incompatible with "Matcher[str]"
          TypeVar "[email protected]" is invariant
            "Sized" is incompatible with "str" (reportGeneralTypeIssues)
    1 error, 0 warnings, 0 informations
    Completed in 0.582sec
    

    Changing line 3 to T = TypeVar('T', contravariant=True) fixes the issue.

    python version: 3.10.8 pyhamcrest version: 2.0.4 pyright version: 1.1.280

    opened by mezuzza 7
  • equal_to describes itself incompletely

    equal_to describes itself incompletely

    Consider how equal_to describes itself:

    >>> d = StringDescription()
    >>> d.append_description_of(equal_to(3))
    <hamcrest.core.string_description.StringDescription object at 0x7fd8de172c40>
    >>> str(d)
    '<3>'
    

    What does <3> mean? It's hard to tell. Compare this with other built-in matcher self-descriptions:

    >>> d = StringDescription()
    >>> d.append_description_of(greater_than(3))
    <hamcrest.core.string_description.StringDescription object at 0x7fd8de0c0d90>
    >>> str(d)
    'a value greater than <3>'
    
    feature request 
    opened by exarkun 1
  • object comparison override

    object comparison override

    Hi there, I am new to Hamcrest and would like to know if there is an example to override the standard object comparison equal operator. I basically have to change the list comparison for the properties of the object otherwise the default one is order dependent. Cheers.

    opened by priamai 3
  • contains_inanyorder fails although I would expect it to pass

    contains_inanyorder fails although I would expect it to pass

    version 2.0.2

    assert_that(['a',4], contains_inanyorder(*[greater_than(0), 'a']))
    Expected: a sequence over [a value greater than <0>, 'a'] in any order
         but: was <['a', 4]>
    

    I would expect is to pass as the definition of the matcher is: "This matcher iterates the evaluated sequence, seeing if each element satisfies any of the given matchers."

    Reason for thie behavior is that:

    class MatchInAnyOrder(object):
    [...]
            def ismatched(self, item: T) -> bool:
            for index, matcher in enumerate(self.matchers):
                if matcher.matches(item):
                    del self.matchers[index]
                    return True
    

    matcher.matches(item) throughs a TypeErrror when running a against greater_than(0 TypeError: '>' not supported between instances of 'str' and 'int'

    Maybe it should be catched like
    try:
               if matcher.matches(item):
                   del self.matchers[index]
                   return True
    except:
               pass
    

    What is curious though is that it is catched here:

    class IsSequenceContainingInAnyOrder(BaseMatcher[Sequence[T]]):
        def __init__(self, matchers: Sequence[Matcher[T]]) -> None:
            self.matchers = matchers
    
        def matches(
            self, item: Sequence[T], mismatch_description: Optional[Description] = None
        ) -> bool:
            try:
                sequence = list(item)
                matchsequence = MatchInAnyOrder(self.matchers, mismatch_description)
                for element in sequence:
                    if not matchsequence.matches(element):
                        return False
                return matchsequence.isfinished(sequence)
            except TypeError:
                if mismatch_description:
                    super(IsSequenceContainingInAnyOrder, self).describe_mismatch(
                        item, mismatch_description
                    )
                return False
    

    But is this the correct and expected behaviour though?

    matcher bug good first issue 
    opened by redsox10 5
Releases(V2.0.3)
Browser reload with uvicorn

uvicorn-browser This project is inspired by autoreload. Installation pip install uvicorn-browser Usage Run uvicorn-browser --help to see all options.

Marcelo Trylesinski 64 Dec 17, 2022
Multi-asset backtesting framework. An intuitive API lets analysts try out their strategies right away

Multi-asset backtesting framework. An intuitive API lets analysts try out their strategies right away. Fast execution of profit-take/loss-cut orders is built-in. Seamless with Pandas.

Epymetheus 39 Jan 06, 2023
Show coverage stats online via coveralls.io

Coveralls for Python Test Status: Version Info: Compatibility: Misc: coveralls.io is a service for publishing your coverage stats online. This package

Kevin James 499 Dec 28, 2022
Percy visual testing for Python Selenium

percy-selenium-python Percy visual testing for Python Selenium. Installation npm install @percy/cli: $ npm install --save-dev @percy/cli pip install P

Percy 9 Mar 24, 2022
🏃💨 For when you need to fill out feedback in the last minute.

BMSCE Auto Feedback For when you need to fill out feedback in the last minute. 🏃 💨 Setup Clone the repository Run pip install selenium Set the RATIN

Shaan Subbaiah 10 May 23, 2022
UX Analytics & A/B Testing

UX Analytics & A/B Testing

Marvin EDORH 1 Sep 07, 2021
User-interest mock backend server implemnted using flask restful, and SQLAlchemy ORM confiugred with sqlite

Flask_Restful_SQLAlchemy_server User-interest mock backend server implemnted using flask restful, and SQLAlchemy ORM confiugred with sqlite. Backend b

Austin Weigel 1 Nov 17, 2022
Test python asyncio-based code with ease.

aiounittest Info The aiounittest is a helper library to ease of your pain (and boilerplate), when writing a test of the asynchronous code (asyncio). Y

Krzysztof Warunek 55 Oct 30, 2022
An interactive TLS-capable intercepting HTTP proxy for penetration testers and software developers.

mitmproxy mitmproxy is an interactive, SSL/TLS-capable intercepting proxy with a console interface for HTTP/1, HTTP/2, and WebSockets. mitmdump is the

mitmproxy 29.7k Jan 02, 2023
Data-Driven Tests for Python Unittest

DDT (Data-Driven Tests) allows you to multiply one test case by running it with different test data, and make it appear as multiple test cases. Instal

424 Nov 28, 2022
RAT-el is an open source penetration test tool that allows you to take control of a windows machine.

To prevent RATel from being detected by antivirus, please do not upload the payload to TOTAL VIRUS. Each month I will test myself if the payload gets detected by antivirus. So you’ll have a photo eve

218 Dec 16, 2022
Aioresponses is a helper for mock/fake web requests in python aiohttp package.

aioresponses Aioresponses is a helper to mock/fake web requests in python aiohttp package. For requests module there are a lot of packages that help u

402 Jan 06, 2023
pytest plugin for a better developer experience when working with the PyTorch test suite

pytest-pytorch What is it? pytest-pytorch is a lightweight pytest-plugin that enhances the developer experience when working with the PyTorch test sui

Quansight 39 Nov 18, 2022
A Library for Working with Sauce Labs

Robotframework - Sauce Labs Plugin This is a plugin for the SeleniumLibrary to help with using Sauce Labs. This library is a plugin extension of the S

joshin4colours 6 Oct 12, 2021
A pytest plugin that enables you to test your code that relies on a running Elasticsearch search engine

pytest-elasticsearch What is this? This is a pytest plugin that enables you to test your code that relies on a running Elasticsearch search engine. It

Clearcode 65 Nov 10, 2022
pytest splinter and selenium integration for anyone interested in browser interaction in tests

Splinter plugin for the pytest runner Install pytest-splinter pip install pytest-splinter Features The plugin provides a set of fixtures to use splin

pytest-dev 238 Nov 14, 2022
Load Testing ML Microservices for Robustness and Scalability

The demo is aimed at getting started with load testing a microservice before taking it to production. We use FastAPI microservice (to predict weather) and Locust to load test the service (locally or

Emmanuel Raj 13 Jul 05, 2022
Python Webscraping using Selenium

Web Scraping with Python and Selenium The code shows how to do web scraping using Python and Selenium. We use as data the https://sbot.org.br/localize

Luís Miguel Massih Pereira 1 Dec 01, 2021
Lightweight, scriptable browser as a service with an HTTP API

Splash - A javascript rendering service Splash is a javascript rendering service with an HTTP API. It's a lightweight browser with an HTTP API, implem

Scrapinghub 3.8k Jan 03, 2023