Skip to content

Commit

Permalink
More special tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ankur-gupta committed Jun 20, 2023
1 parent 31e674d commit a4f2aa4
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
16 changes: 16 additions & 0 deletions tests/test_how_to_import_from_package.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import pytest

# You can import from the package any way you want.
# Test a function that is intended to be used by the end user.
from rain import this_function_will_be_imported

# Test a function that is NOT intended to be used by the end user.
from rain.directory_module_with_selective_imports.utils import helper_function_1


def test_end_user_usable():
assert isinstance(this_function_will_be_imported(), str)


def test_helper_function_1():
assert helper_function_1() == 'helper_function_1'
14 changes: 14 additions & 0 deletions tests/test_naming_conventions.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,17 @@ def test_this_is_a_test():
assert 1 == 1


class ThisIsNotATestClass:
def test_method(self):
# Since this is not a test class, the following assert statement won't fail
assert 1 == 2


class TestClass:
def this_is_not_a_test_method(self):
# Since this is not a test method, the following assert statement won't fail
assert 1 == 2

def test_method(self):
# Try changing this to `assert 1 == 2` to see that this method is indeed being tested
assert 1 == 1
27 changes: 27 additions & 0 deletions tests/test_using_a_class.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import pytest


class TestClassNoConstructor:
# Setup anything that you need to test.
x = 1

def test_x_is_one(self):
# Change this to `assert 1 == 2` to see that this method is indeed being tested
assert self.x == 1


class TestClassWithConstructor:
# Having a constructor means that this class won't be tested. Instead, you will see this warning:
#
# PytestCollectionWarning: cannot collect test class 'TestClassWithConstructor' because it has a
# __init__ constructor (from: tests/test_using_a_class.py)
# class TestClassWithConstructor:
#
# -- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
def __init__(self, x: int):
self.x = int(x)

def test_will_not_run(self):
# This test won't run because this class has a constructor
assert 1 == 2

0 comments on commit a4f2aa4

Please sign in to comment.