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.

unittest gives error

See original GitHub issue

Hi there, and thanks for a great tool.

I was trying to use unittest (which is part of the PSL) with the following program:

import unittest
    
def sort_i(unsortedArray,direction="ASC"):
    sortedArray = [];
    for i in unsortedArray[1:]:
        print i
    return sortedArray

class TestSortInsertion(unittest.TestCase):

    def test_base(self):
        self.assertEqual(sort_i([1,3,4,2]), [1,2,3,4])

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

But I get the following error:

Fprocessing.app.SketchException: AttributeError: FakeStdErr instance has no attribute 'flush'
	at jycessing.mode.run.SketchRunner.convertPythonSketchError(SketchRunner.java:240)
	at jycessing.mode.run.SketchRunner.access$4(SketchRunner.java:227)
	at jycessing.mode.run.SketchRunner$3.run(SketchRunner.java:122)
	at java.lang.Thread.run(Thread.java:748)

Any idea?

thanks a lot

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:11 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
jeremydouglasscommented, Nov 26, 2017

Thank you so much – for the patch, and for the workaround, which I can confirm is working for me.

I have put together a related demo sketch for Processing.py users who want to use unittest (not as main) in a normal sketch, e.g. from setup() or on keyPressed(). I haven’t really begun using it myself, so feedback most welcome.

https://github.com/jeremydouglass/processingpy_unittest

0reactions
jeremydouglasscommented, Nov 26, 2017

Good suggestion – I bundled it into a collection repo called processingpy_import_examples and linked to it on the forum.

Read more comments on GitHub >

github_iconTop Results From Across the Web

unittest — Unit testing framework — Python 3.11.1 ...
Unittest supports skipping individual test methods and even whole classes of tests. In addition, it supports marking a test as an “expected failure,”...
Read more >
Python unittest: make AssertionError an error instead of a failure
failureException : This class attribute gives the exception raised by the test method. If a test framework needs to use a specialized exception, ......
Read more >
Test if a function throws an exception in Python - GeeksforGeeks
The test passes if exception is raised, gives an error if another exception is raised, or fails if no exception is raised.
Read more >
How to catch a raise error in python unittest - YouTube
When you developer your code and want to test somthing there crash you code so its not react wirdt you mabey use raise...
Read more >
Fix Installation Error of 'unittest' - Finxter
The following video shows you how to resolve the ImportError : How to Fix : “ImportError: Cannot import name X” in Python?
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