question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Freeze when comparing byte data with verbose flag

See original GitHub issue

When comparing a lot of byte data (like two images), pytest will look frozen when using the -v flag. Not sure if this is a bug, but I at least wanted to document this behaviour.

To clarify this, here is the code making problems

def test_compare():
    with open('one.png', "rb") as f:
        actual_image = f.read()

    with open('two.png', "rb") as f:
        expected_image = f.read()

    assert actual_image == expected_image

Assuming that both images are different, running this code with “pytest -s” will take a view milliseconds, but running it with “pytest -s -v” took 12 minutes on my computer.

A workaround is to put the comparison in an own variable

def test_compare():
    with open('one.png', 'rb') as f:
        actual_image = f.read()

    with open('two.png', 'rb') as f:
        expected_image = f.read()

    result = actual_image == expected_image
    assert result

Running this will take a view milliseconds only, no matter if the assertion fails or succeeds.

I have attached an example workspace.

By the way you will also run into this issue when executing the tests using the pytest runner of PyCharm.

freezing_assertion.zip

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:10 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
The-Compilercommented, Aug 15, 2021

Might be a duplicate of #7206?

0reactions
Zac-HDcommented, Sep 27, 2021

Closing as duplicate; per https://github.com/pytest-dev/pytest/issues/8998#issuecomment-900389987 we should try adding a heuristic that skips difflib.ndiff() for sequences above a fixed length (tbd based on some benchmarks).

Read more comments on GitHub >

github_iconTop Results From Across the Web

BytesMut in bytes - Rust - Docs.rs
pub fn freeze(self) -> Bytes​​ Converts self into an immutable Bytes . The conversion is zero cost and is used to indicate that...
Read more >
Memory error checking in C and C++: Comparing Sanitizers ...
This article compares two tools, Sanitizers and Valgrind, that find memory bugs in programs written in memory-unsafe languages.
Read more >
Byte - Android Developers
Byte ; Byte. Public methods. byteValue; compare; compareTo; compareUnsigned; decode; doubleValue; equals; floatValue; hashCode; hashCode; intValue; longValue ...
Read more >
Tune and Troubleshoot Oracle Data Guard
Obtain the redo generation history from the primary database and compare that to when the redo transport or redo apply lag started. Check...
Read more >
stress-ng - a tool to load and stress a computer system
--syslog log output (except for verbose -v messages) to the syslog. ... hash on 128 rounds of 128..1 bytes of random data jmp...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found