Chris Padilla/Blog

My passion project! Posts spanning music, art, software, books, and more
You can follow by Newsletter or RSS! (What's RSS?) Full archive here.

    Testing with Pytest

    A quick start guide:

    1. Install Pytest through pip.
    2. When running your tests, call it through the command line:
    python3.7 -m pytest .

    There's documentation for calling it globally, but I had no luck. Calling it through the same version of python with the -m flag did the trick for me.

    1. Write your test file!
    import pytest
    
    @pytest.fixture(scope='class')
    def my_tests_init(request):
        # Set up DB connection here
    
        try:
            # Insert any sample date
        except Exception as e:
            # Handle exceptions
    
        yield # Your tests will happen here
    
        # Tear down: remove sample data from db.
        # Close DB

    Pytest will use decorators to add in the functionality needed to interpret your file correctly.

    All your tests will live in a class like this one:

    @pytest.mark.usefixtures("my_tests_init")
    class TestMyClass:
    
        def test_my_method(self):
            expected = [{'cool': True}]
    
            result = self.my_class.my_method()
            assert result == expected

    Here, the decorator ensures the the init method runs before and after these tests.

    From there, test methods must start with "test" in the method name.

    And you do your thing from there!

    Pytest, unlike testing libraries like unittest or Jest in JS, doesn't use assertion methods. Here we just have the assert keyword being used against a boolean expression. Even if we use a reference type, Pytest will know to assert the values of the dictionary or list deeply.

    Additionally: If you're not finding what you need from the command line error logs, adding the v flag will give you a closer look, while vv gives you even more details. vv Goes as far to show a git-like comparison, line by line, of what conflicts between your expected and actual results!

    Sketchbook No. 5 Down!

    📝

    Another one down!!

    Started off very exercise heavy. These are figure study simplifications of the torso here:

    🫘

    Explored a few animal charicatures:

    🦉

    🐘

    And then finished the book out with meditative automatic drawing:

    🧘

    My next one is a bigger sketchbook, so I'm excited to have more room to play. :)

    Automatic Drawing

    Something I'm still learning is to keep more play in all of my creative practices.

    Maybe that's surprising to anyone looking in from what I share! But it's true — it's still a challenge to turn off the critical brain when I'm playing an instrument or drawing.

    With drawing, I was just doodling and messing with shape at the start. Lately, I've caught myself leaning more towards filling all of my drawing time with exercises and course. If I'm aiming for the 50% rule, I'm really only hitting 25% play. Not entirely a bad thing, but it leaves little room for experimentation and just enjoying the act of drawing.

    An experiment I'm trying out to really loosen up is automatic drawing, as demonstrated by Tim Gula here:

    Watch on Youtube

    The end result is beautiful, but the result isn't really the point. Its meditation for the mind, playing purely with shape, line, and values.

    The irony is that, in messing around, a lot of growth happens at the same time: Line quality improves, control over shape develops, and a relaxed brain allows for those periods of focus to be more energized.

    Most exciting for me, though, is that when I'm just doodling outside of any coursework, I can shrug off the pressure of it having to be impressive. There's room for experimentation and simply enjoying putting pencil to paper!

    I'm trying this out with music too. Lately, I've been spending all my piano and guitar time playing out of books, leaving no time to write or improvise. So now I have a notebook for jotting down improvised chords, melodies, and mini-tunes. Not with the goal of making another album. Just for the space to enjoy sound unto itself.

    At the end of the day, sound and line are purpose enough.

    Winston Churchill on Painting as a Pastime

    I don't always find the inspiration I'm looking for from the bios and stories of full time artists. Those select few who can spend most of their week in the studio. Winston Churchill, who was surprisingly an enthusiastic, self proclaimed hobby painter, can speak much more clearly to the situation of having to find time to be creative in the nooks and crannies of the day.

    And a surprisingly sensitive painter, at that!!

    I've been rattling in my mind all the different reasons I like drawing/piano/guitar/writing music/blogging, and why someone else might like to do them too.

    To Churchill, it was no contest comparing painting to more typical leisure activities:

    Even at the advanced age of Forty! It would be a sad pity to shuffle or scramble along through one's playtime with golf and bridge, pottering, loitering, shifting from one heel to the other, wondering what on earth to do – as perhaps is the fate of some unhappy beings – when all the while, if you only knew, there is close at hand a wonderful new world of thought and craft, a sunlit garden gleaming with light and colour of which you have the key in your waistcoat pocket. Inexpensive independence, a mobile and perennial pleasure apparatus, new mental food and exercise, the old harmonies and symmetries in an entirely different language, an added interest to every common scene, an occupation for every idle hour, an unceasing voyage of entrancing discovery – these are high prizes.

    A particularly sobering passage acknowledges that, as a hobbyist, you won't reach the same great heights of technique as the life-long, full time painters. It's a problem I find myself wrestling with frequently, but Churchill brings it up so matter-of-factly and without much concern:

    But if, on the contrary, you are inclined – late in life though it be – to reconnoitre a foreign sphere of limitless extent, then be persuaded that the first quality that is needed is Audacity. There really is no time for the deliberate approach. Two years of drawing-lessons, three years of copying woodcuts, five years of plaster casts – these are for the young. They have enough time to bear. And this thorough grounding is for those who, hearing the call in the morning of their days, are able to make painting their paramount lifelong vocation. The truth and beaut of line and form which by the slightest touch or twist of the brush a real artist imparts to every feature of his design must be founded on long, hard, persevering apprenticeship and a practice so habitual that it has become instinctive. We must not be too ambitious. We cannot aspire to masterpieces. We may content ourselves with a joy ride in a paintbox. And for this Audacity is the only ticket.

    These trees ❤️

    It's still worth the pursuit all the same. The rewards for that Audacity are many:

    I have written in this way to show how varied are the delights which may be gained by those who enter hopefully and thoughtfully upon the pathway of painting; how enriched they will be in their daily vision, how fortified in their independence, how happy in their leisure. Whether you feel that your soul is pleased by the conceptions or contemplation of harmonies, or that your mind is stimulated by the aspect of magnificent problems, or whether you are content to find fun in trying to observe and depict the jolly things you see, the vistas of possibility are limited only by the shortness of life. Every day you may make progress. Every step may be fruitful. Yet there will stretch out before you an ever-lengthening, ever-ascending, ever-improving path. You know you will never get to the end of the journey. But this, so far from discouraging, only adds to the joy and glory of the climb.

    So beautifully said. It all rings true for me:

    • Playing with shapes and sound, their interaction with one another, is fun unto itself
    • Creation is largely puzzle solving. Even playing piano is a finger puzzle
    • There's no better way to express love for the world than to try to recapture it as you see it
    • Progress, itself, is a joy! Learning an instrument more intimately or refining a line stroke, they all lead to small victories
    • There are infinite paths to explore. None right or wrong, only guided by your curiosity and interest

    And why wait? The time to plant a garden is now:

    Try it, then, before it is too late and before you mock at me. Try it while there is time to overcome the preliminary difficulties. Learn enough of the language in your prime to open this new literature to your age. Plant a garden in which you can sit when digging days are done. It may be only a small garden, but you will see it grow. Year by year it will bloom and ripen. Year by year it will be better cultivated. The weeds will be cast out. The fruit-trees will be pruned and trained. The flowers will bloom in more beautiful combinations. There will be sunshine there even in the winter-time, and cool shade, and the play of shadow on the pathway in the shining days of June.

    While the earlier, the better for overcoming the initial hurdle of learning the vocabulary, it's never too late. Thankfully, the barrier to entry is not technique or years of experience. Just Audacity!

    ☁️

    Faber - This One is About Cats

    Listen on Youtube

    The little rascals! 🐈