Skip to content

Commit

Permalink
Merge pull request #72 from pybee/pytest
Browse files Browse the repository at this point in the history
Add a PyTest backend for cricket.
  • Loading branch information
freakboy3742 committed Jun 24, 2018
2 parents f31eacb + a3b7fb9 commit e491fae
Show file tree
Hide file tree
Showing 72 changed files with 2,789 additions and 466 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
# Tests
.coverage
.tox
.pytest_cache

# Distribution
env/
dist/
build/
*.egg-info
.eggs
_build
distribute-*

Expand Down
6 changes: 4 additions & 2 deletions beekeeper.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ pull_request:
- smoke-test:
task: py35
name: Smoke build (Python 3.5)
environment:
EXTRA_REQUIRES: pytest>=3.6 django~=1.11
# - full-test:
# subtasks:
# - py3.5:
Expand All @@ -18,5 +20,5 @@ pull_request:
# task: py36
push:
- smoke-test:
task: py34
name: Smoke build (Python 3.4)
task: py35
name: Smoke build (Python 3.5)
1 change: 0 additions & 1 deletion cricket/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ def main(Model):

parser.add_argument("--version", help="Display version number and exit", action="store_true")

Model.add_arguments(parser)
options = parser.parse_args()

# Check the shortcut options
Expand Down
8 changes: 6 additions & 2 deletions cricket/django/__main__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
'''
This is the main entry point for running Django test suites.
'''
from cricket.main import main as cricket_main
from cricket.app import main as cricket_main
from cricket.django.model import DjangoTestSuite


def main():
return cricket_main(DjangoTestSuite)


if __name__ == "__main__":
def run():
main().main_loop()


if __name__ == "__main__":
run()
15 changes: 0 additions & 15 deletions cricket/django/discoverer.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
from __future__ import absolute_import

import unittest

from django.conf import settings
try:
from django.test.simple import DjangoTestSuiteRunner
except ImportError:
DjangoTestSuiteRunner = None
from django.test.utils import get_runner

# Dynamically retrieve the test runner class for this project.
Expand All @@ -20,17 +14,8 @@ class TestDiscoverer(TestRunnerClass):
"""
def _output_suite(self, suite):
for test in suite:
# Django 1.6 introduce the new-style test runner.
# If that test runner is in use, we use the full test name.
# If we're still using a pre 1.6-style runner, we need to
# drop out all everything between the app name and the test module.
if isinstance(test, unittest.TestSuite):
self._output_suite(test)
elif (DjangoTestSuiteRunner
and issubclass(TestRunnerClass, DjangoTestSuiteRunner)):
parts = test.id().split('.')
tests_index = parts.index('tests')
print('%s.%s.%s' % (parts[tests_index - 1], parts[-2], parts[-1]))
else:
print(test.id())

Expand Down
8 changes: 5 additions & 3 deletions cricket/django/django_runtests.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#!/usr/bin/env python
# A command line tool that passes in a custom runner for running
# Django's own internal unit tests.
import importlib
import os
import warnings
import argparse

from django.utils import importlib

# This is Django's runtest module
# (the one you use to run Django's test suite)
import runtests


Expand Down
9 changes: 1 addition & 8 deletions cricket/django/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,7 @@ class TestExecutor(TestRunnerClass):
Formats output in a machine-readable format.
"""
def run_suite(self, suite, **kwargs):
# Django 1.6 introduce the new-style test runner.
# If that test runner is in use, we use the full test name.
# If we're still using a pre 1.6-style runner, we need to
# drop out all everything between the app name and the test module.
use_old_discovery = (DjangoTestSuiteRunner and
issubclass(TestRunnerClass, DjangoTestSuiteRunner))

return PipedTestRunner(use_old_discovery=use_old_discovery).run(suite)
return PipedTestRunner().run(suite)


class TestCoverageExecutor(TestExecutor):
Expand Down
19 changes: 18 additions & 1 deletion cricket/django/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import os
import sys

from cricket.model import TestSuite
from cricket.model import TestSuite, TestModule, TestCase, TestMethod


class DjangoTestSuite(TestSuite):
Expand Down Expand Up @@ -72,3 +72,20 @@ def execute_commandline(self, labels):
command.extend(labels)

return command

def split_test_id(self, test_id):
pathparts = test_id.split('.')

return [
(TestModule, part)
for part in pathparts[:-2]
] + [
(TestCase, pathparts[-2]),
(TestMethod, pathparts[-1]),
]

def join_path(self, parent, klass, part):
if parent.path is None:
return part
else:
return '{}.{}'.format(parent.path, part)
2 changes: 1 addition & 1 deletion cricket/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ async def run(self, count, labels):
try:
# No active test; first line tells us which test is running.
pre = json.loads(line)
self.current_test = self.test_suite.confirm_exists(pre['path'])
self.current_test = self.test_suite.put_test(pre['path'])

# Update the display
if self.display:
Expand Down

0 comments on commit e491fae

Please sign in to comment.