I encountered a problem with unit tests when use i18 in my project. My project uses framewoks i18 and webapp2 The function uses the translation by i18. But when I test, I get the error – missing global variable request. For example it is: and I have message: I have a solution to this problem, but I do not like
Tag: unit-testing
Test discovery failure when tests in different directories are called the same
Using py.test, two tests called the same in different directory causes py.test to fail. Why is that? How can I change this without renaming all the tests? To duplicate do: Answer Putting an __init__.py is one way of resolving the conflict. Unlike nose, current pytest does not try to unload test modules in order to import test modules with the
How do I structure my tests with the Python ‘unittest’ module?
I’m trying to build a test framework for automated web testing in Selenium and unittest, and I want to structure my tests into distinct scripts. So I’ve organised it as following: File base.py – this will contain, for now, the base Selenium test case class for setting up a session. File main.py – I want this to be the overall
How to exclude a file from coverage.py?
I use nosetest’s coverage.py plugin. Is it somehow possible to exclude entire files or folders from the coverage report? My use case is having an external library in my project folder that obviously isn’t covered by my test suite. Answer Yeah, they have pretty extensive support for this in the docs. When running your code, the coverage run command will
Python import src modules when running tests
My source files are located under src and my test files are located under tests. When I want to run a test file, say python myTest.py, I get an import error: “No module named ASourceModule.py”. How do I import all the modules from source needed to run my tests? Answer You need to add that directory to the path: Maybe
Python unittest – opposite of assertRaises?
I want to write a test to establish that an Exception is not raised in a given circumstance. It’s straightforward to test if an Exception is raised … … but how can you do the opposite. Something like this i what I’m after … Answer
Proper way to test Django signals
I’m trying to test sent signal and it’s providing_args. Signal triggered inside contact_question_create view just after form submission. My TestCase is something like: Is this the proper way to test this signal? Any better ideas? Answer I’ve resolved the problem by myself. I think that the best solution is following:
Python unit test with base and sub class
I currently have a few unit tests which share a common set of tests. Here’s an example: The output of the above is: Is there a way to rewrite the above so that the very first testCommon is not called? EDIT: Instead of running 5 tests above, I want it to run only 4 tests, 2 from the SubTest1 and