Freeze when comparing byte data with verbose flag
See original GitHub issueWhen 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.
Issue Analytics
- State:
- Created 3 years ago
- Comments:10 (10 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Might be a duplicate of #7206?
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).