Skip to content

Commit

Permalink
Allow running tests without the presence of a fixtures module
Browse files Browse the repository at this point in the history
  • Loading branch information
ccrisan committed Jul 30, 2019
1 parent bdf73e0 commit ecb6817
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
6 changes: 5 additions & 1 deletion colibris/commands/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os

from colibris.conf import settings
from colibris.utils import import_module_or_none

from .base import BaseCommand

Expand Down Expand Up @@ -56,7 +57,10 @@ def execute(self, options):
os.chdir(tests_dir)

plugins = list(_PLUGINS)

# Use project's fixtures as a plugin so that project-specific fixtures are loaded
plugins.append('{}.tests.fixtures'.format(settings.PROJECT_PACKAGE_NAME))
fixtures_path = '{}.tests.fixtures'.format(settings.PROJECT_PACKAGE_NAME)
if import_module_or_none(fixtures_path):
plugins.append(fixtures_path)

return pytest.main(args, plugins=plugins)
1 change: 1 addition & 0 deletions colibris/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def import_member(path):


def import_module_or_none(path):
# TODO py36 remove this workaround
# In Python < 3.6 we don't have ModuleNotFoundError
ModuleNotFoundError = getattr(builtins, 'ModuleNotFoundError', ImportError)

Expand Down

1 comment on commit ecb6817

@lucifurtun
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good!

Please sign in to comment.