4

I have written a small utility package for handling file permissions. The structure follows the Python package standards:

.
|-- __init__.py                     # All the code is here, for now
`-- tests
    |-- __init__.py
    |-- permission_mode.feature     # Feature files for behave
    |-- steps                       
    |   |-- __init__.py
    |   `-- steps.py                # Step files for behave
    `-- test_modtools.py            # Nose tests

Both nose and behave run the tests from the command line without issues:

Nose:

$ nosetests
.
----------------------------------------------------------------------
Ran 1 test in 0.002s

OK

Behave:

$ behave
Feature: Lots of cheese # permission_mode.feature:1

  Scenario: blah  # permission_mode.feature:2
    Given a       # steps/steps.py:1 0.000s
    Then b        # steps/steps.py:5 0.000s

1 feature passed, 0 failed, 0 skipped
1 scenario passed, 0 failed, 0 skipped
2 steps passed, 0 failed, 0 skipped, 0 undefined
Took 0m0.000s

My setup.py file contains the following test spec:

test_suite='nose.collector',
tests_require=['nose']

And therefore python setup.py test runs nose tests with the same output as nosetests.

How do I configure behave as the package's test tool, so that python setup.py test will run behave?

2 Answers 2

3

Look at "setup.py" from behave. It contains the usage of the colocated "setuptools_behave.py" test runner (and installs it).

RECIPE FOR USAGE:

# -- file:setup.py
from setuptools_behave import behave_test
...

setup(
    ...
    tests_require=["behave>=1.2.4"],
    cmdclass = {
        "behave_test": behave_test,
    },
    ...    
)

To verify it, execute "python setup.py --help-commands". It should contain a command "behave_test". Otherwise, run "python setup.py behave_test --help".

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks! I've added this to my setup.py, and had two problems: a. behave_test does not install the packages in tests_require, so I have to install behave manually. b. After installing behave, python setup.py behave_test gives can't open file 'behave': [Errno 2] No such file or directory. This happens both with and without a virtual environment.
And thanks again for the attention. It's always a pleasure to get an answer from the actual developer.
1

Look this commit Provide simple test runner to run behave tests from setup.py.

Maybe for next release?

1 Comment

Thanks, that's good news. I have downloaded the latest code from github, and there are still some bugs with virtual environments. I tried hacking it a bit and changing sys.executable in line 124 to os.path.dirname(sys.executable), but it didn't solve the problem. Will open a ticket. github.com/behave/behave/blob/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.