Effective PyCharm Transcripts
Chapter: Unit testing
Lecture: Running pytest tests
Login or
purchase this course
to watch this video and the rest of the course contents.
0:00
Before we actually write our test, let's just get everything kind of put together in place, so over here I'm going to add a Python file
0:08
I'm going to call this something super exciting like tests, like this and in here we're going to be using pytest.
0:17
Alright, so we're going to import pytest, now pytest does not come with Python, it's external so it's over here in the requirements.txt
0:26
and so you want to make sure that you install that for this to work, so we're going to have pytest and we're also going to import core
0:35
and notice this is the root here, so that's going to work, this file is looking up for that one, so that's the source root, this should work,
0:44
and down here the way we work with pytest is we just define a method it has the word test and then other, it has some stuff in it
0:52
and then we can just assert, we can assert true, we can assert false, whatever so, we're going to just make sure that we can run this
1:03
now if this was based on unit tests if this is a class called tests deriving from unittest.TestCase I believe
1:11
then I could come over here and right click in PyCharm and say run unit tests in here I don't think it's going to do what we're looking for here,
1:20
not so much is it, so we can't run it that way however, let's go and fix this, let's get rid of that one
1:27
and we'll stay I would like to add a Python test run and notice all the different options,
1:32
Twisted Trial, unit tests that's one I was talking about, pytest, okay great and what are we going to run, we are going to run a particular file
1:40
sadly we have to browse all over the place I do wish that would remember its location let us select this, that seems wrong doesn't it,
1:50
let's do it this way, copy path and enter path. There should be no more arguments we're going to use the same virtual environment
2:03
and let's use the same working directory just in case, oh yeah, and name, let's call this table test, try again, look, now we have the test runner,
2:18
so we have all the tests are passed and we can expand those out and we can see here is this module called test
2:26
it had one successful dot, and here is our other and if there was output from it, you would see that down here.
2:31
So we haven't actually done any testing yet but we have the infrastructure here and we can rerun those tests
2:37
and we can right click and say run just this one or profile just that one or check the concurrency diagram
2:42
or run it with coverage, all sorts of cool stuff even just jump to the source which is hey no surprise right there, it's the one we wrote.
2:51
So now everything in place, we're going to actually write some test methods involving our actual application.