-
Notifications
You must be signed in to change notification settings - Fork 221
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ability to automatically collect *.feature files
- Loading branch information
Showing
5 changed files
with
88 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import sys | ||
|
||
try: | ||
from types import ModuleType | ||
except ImportError: | ||
ModuleType = type(sys) | ||
|
||
from _pytest.python import Module | ||
from .scenario import scenarios | ||
|
||
|
||
class PytestBDDModule(Module): | ||
""" | ||
Class that represents *.feature file as python module | ||
""" | ||
|
||
def _getobj(self): | ||
# Add _test suffix to module name | ||
module_name = self.nodeid.replace("/", ".").rsplit(".", 1)[0] + "_test" | ||
|
||
# Create dummy module to store tests | ||
module = ModuleType( | ||
name=module_name, doc="Autogenerated python module for {!r} feature file".format(str(self.fspath)) | ||
) | ||
sys.modules[module_name] = module | ||
|
||
# Add scenarios for dummy module | ||
scenarios(self.fspath.basename, features_base_dir=self.fspath.dirname, module=module) | ||
|
||
return module |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
"""Auto collect tests.""" | ||
import pytest | ||
|
||
import textwrap | ||
|
||
|
||
@pytest.fixture | ||
def auto_collect_test_dir(testdir): | ||
dirname = "test_auto_collect" | ||
tests = testdir.mkpydir(dirname) | ||
|
||
tests.join("foo.feature").write( | ||
textwrap.dedent( | ||
r""" | ||
Feature: The feature | ||
Scenario: Some scenario | ||
""" | ||
) | ||
) | ||
|
||
|
||
def test_auto_collect_tests(auto_collect_test_dir, testdir): | ||
testdir.makeini( | ||
""" | ||
[pytest] | ||
bdd_auto_collect=true | ||
""" | ||
) | ||
|
||
result = testdir.runpytest() | ||
|
||
result.stdout.fnmatch_lines("collected 1 item") | ||
result.assert_outcomes(passed=1) | ||
|
||
|
||
def test_auto_collect_tests_disabled(auto_collect_test_dir, testdir): | ||
result = testdir.runpytest() | ||
|
||
result.stdout.fnmatch_lines("collected 0 items") |