Different db for testing in Django?
In your settings.py (or local_settings.py): import sys if ‘test’ in sys.argv: DATABASES[‘default’] = { ‘ENGINE’: ‘django.db.backends.sqlite3’, ‘NAME’: ‘mydatabase’ }
In your settings.py (or local_settings.py): import sys if ‘test’ in sys.argv: DATABASES[‘default’] = { ‘ENGINE’: ‘django.db.backends.sqlite3’, ‘NAME’: ‘mydatabase’ }
Take a look at Parameterized Tests in JUnit 4. Actually I did this a few days ago. I’ll try to explain … First build your test class normally, as you where just testing with one input file. Decorate your class with: @RunWith(Parameterized.class) Build one constructor that takes the input that will change in every test … Read more
A related problem that I found is that surefire in recent versions apparently sets trimStackTrace to true by default (rendering most stack trace in failed tests useless), which is quite inconvenient. Setting -DtrimStackTrace=false or defining <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <configuration> <trimStackTrace>false</trimStackTrace> </configuration> </plugin> solved this.
I think the better way is to mock the property as PropertyMock, rather than to mock the __get__ method directly. It is stated in the documentation, search for unittest.mock.PropertyMock: A mock intended to be used as a property, or other descriptor, on a class. PropertyMock provides __get__ and __set__ methods so you can specify a … Read more
Readability is more important for tests. If a test fails, you want the problem to be obvious. The developer shouldn’t have to wade through a lot of heavily factored test code to determine exactly what failed. You don’t want your test code to become so complex that you need to write unit-test-tests. However, eliminating duplication … Read more
UPDATE Just realized another way to do this that works much better than the –verbose command line option: class TestSomething extends PHPUnit_Framework_TestCase { function testSomething() { $myDebugVar = array(1, 2, 3); fwrite(STDERR, print_r($myDebugVar, TRUE)); } } This lets you dump anything to your console at any time without all the unwanted output that comes along … Read more
Original idea from this answer with a more generic approach. Using a custom DynamicObject as a wrapper for inspecting the value via reflection there was no need to add the InternalsVisibleTo public class DynamicObjectResultValue : DynamicObject, IEquatable<DynamicObjectResultValue> { private readonly object value; public DynamicObjectResultValue(object value) { this.value = value; } #region Operators public static bool … Read more
Sure. Define a class, put the stuff you need inside that, assign the class to sys.modules[“classname”]. class fakemodule(object): @staticmethod def method(a, b): return a+b import sys sys.modules[“package.module”] = fakemodule You could also use a separate module (call it fakemodule.py): import fakemodule, sys sys.modules[“package.module”] = fakemodule
You can put your tests in a tests/ subdirectory of the app (rather than a tests.py file), and include a tests/models.py with the test-only models. Then provide a test-running script (example) that includes your tests/ “app” in INSTALLED_APPS. (This doesn’t work when running app tests from a real project, which won’t have the tests app … Read more
That is because you need to configurate karma to load then serve them when requested 😉 In your karma.conf.js file you should already have defined files and/or patterns like : // list of files / patterns to load in the browser files : [ {pattern: ‘app/lib/angular.js’, watched: true, included: true, served: true}, {pattern: ‘app/lib/angular-*.js’, watched: … Read more