Pass Travis CI test for python click.version_option decorator?

The goal of the test was to simulate a command that looked like main --version .

When I ran this test in my local environment, it passed (along with the others).

$ pytest
============================ test session starts ============================
platform linux -- Python 3.8.3, pytest-5.4.3, py-1.8.1, pluggy-0.13.1
rootdir: /path/to/root/dir
collected 15 items                                                          

tests/test_cli.py ..........                                          [ 66%]
tests/test_contexts.py .                                              [ 73%]
tests/test_models.py .                                                [ 80%]
tests/test_utils.py ...                                               [100%]

============================ 15 passed in 0.30s =============================

However, when Travis tried to build it, this particular test failed. Here’s the debug log from Travis

$ pytest
============================= test session starts ==============================
platform linux -- Python 3.6.7, pytest-5.4.3, py-1.8.1, pluggy-0.13.1
rootdir: /path/to/root/dir
collected 15 items                                                             
tests/test_cli.py ..F.......                                             [ 66%]
tests/test_contexts.py .                                                 [ 70%]
tests/test_models.py .                                                   [ 80%]
tests/test_utils.py ...                                                  [100%]
=================================== FAILURES ===================================
____________________________ test_cli_with_version _____________________________
runner = <click.testing.CliRunner object at 0x7fe288f596a0>
    def test_cli_with_version(runner):
        result = runner.invoke(cli.main, ['--version'])
>       assert result.exit_code == 0
E       AssertionError: assert 1 == 0
E        +  where 1 = <Result RuntimeError('Could not determine version',)>.exit_code
tests/test_cli.py:35: AssertionError
=========================== short test summary info ============================
FAILED tests/test_cli.py::test_cli_with_version - AssertionError: assert 1 == 0
========================= 1 failed, 14 passed in 0.34s =========================
The command "pytest" exited with 1.
Done. Your build exited with 1.

Here’s how .travis.yml file looks like:

language: python
# target python versions
python:
  - "3.6"
  - "3.7"
  - "3.8"
# operating systems
os:
  - linux
  - osx
  - windows
# configure jobs
jobs:
  allow_failures:
    - os: windows
    - os: osx
# install dependencies
install:
  - pip install --upgrade pip
  - pip install -r requirements.txt
# run tests
script:
  - pytest
# target branches for builds
branches:
  only:
    - master

how can I fix this? any help would be appreciated

To another thread and good morning @SolarUltima,

Firstly generate the package metadata so the version can be read from. This can be done in different ways, the minimal being

 python setup.py egg_info

The most efficient way of doing this in my opinion is installing the package in editable mode, so use pip and run:

pip install -editable .

The beauty of Travis is all you have to do is just add another command to the install key value section:

install:
  - pip install -upgrade pip
  - pip install -r requirements.txt
  - pip install -editable .

If you want something more compact, you can even combine all three commands into one via:

- pip install -upgrade pip -r requirements.txt -editable .