当没有 shell 别名时,如何向程序添加隐藏参数?

当没有 shell 别名时,如何向程序添加隐藏参数?

py.test 认为有一个参数,-n但实际上没有。可以添加什么?该程序在 OS X 上按预期运行,但在 Ubuntu 16.04 上却不行。

我检查了许多可能性和别名,尝试过 zsh、sh,但没有成功。

± /usr/local/bin/py.test
usage: py.test [options] [file_or_dir] [file_or_dir] [...]
py.test: error: unrecognized arguments: -n
  inifile: /home/ahundt/src/keras/pytest.ini
  rootdir: /home/ahundt/src/keras
-> [2]
± sh
$ /usr/local/bin/py.test
usage: py.test [options] [file_or_dir] [file_or_dir] [...]
py.test: error: unrecognized arguments: -n
  inifile: /home/ahundt/src/keras/pytest.ini
  rootdir: /home/ahundt/src/keras
$ /usr/local/bin/py.test tests/
usage: py.test [options] [file_or_dir] [file_or_dir] [...]
py.test: error: unrecognized arguments: -n tests/
  inifile: /home/ahundt/src/keras/pytest.ini
  rootdir: /home/ahundt/src/keras
$ exit
-> [2]
ahundt@femur|~/src/keras on tfrecord!?
± pip2 install --upgrade pytest
Collecting pytest
  Downloading pytest-3.2.1-py2.py3-none-any.whl (186kB)
    100% |████████████████████████████████| 194kB 6.4MB/s 
Requirement already up-to-date: setuptools in /usr/local/lib/python2.7/dist-packages (from pytest)
Requirement already up-to-date: py>=1.4.33 in /usr/local/lib/python2.7/dist-packages (from pytest)
Installing collected packages: pytest
  Found existing installation: pytest 3.1.2
    Uninstalling pytest-3.1.2:
      Successfully uninstalled pytest-3.1.2
Successfully installed pytest-3.2.1
ahundt@femur|~/src/keras on tfrecord!?
Requirement already up-to-date: pytest in /usr/local/lib/python2.7/dist-packages
Requirement already up-to-date: setuptools in /usr/local/lib/python2.7/dist-packages (from pytest)
Requirement already up-to-date: py>=1.4.33 in /usr/local/lib/python2.7/dist-packages (from pytest)
± pip3 install --upgrade --user pytest
Collecting pytest
  Using cached pytest-3.2.1-py2.py3-none-any.whl
Collecting setuptools (from pytest)
  Using cached setuptools-36.2.7-py2.py3-none-any.whl
Collecting py>=1.4.33 (from pytest)
  Using cached py-1.4.34-py2.py3-none-any.whl
Installing collected packages: setuptools, py, pytest
Successfully installed py-1.4.34 pytest-3.2.1 setuptools-36.2.7
± py.test tests/
usage: py.test [options] [file_or_dir] [file_or_dir] [...]
py.test: error: unrecognized arguments: -n tests/
  inifile: /home/ahundt/src/keras/pytest.ini
  rootdir: /home/ahundt/src/keras
± type py.test
py.test is /usr/local/bin/py.test
py.test is /home/ahundt/.local/bin/py.test
ahundt@femur|~/src/keras on tfrecord!?
± type /home/ahundt/.local/bin/py.test
/home/ahundt/.local/bin/py.test is /home/ahundt/.local/bin/py.test

答案1

有这样一种说法,即在pytest.ini

# Configuration of py.test
[pytest]
addopts=-v
        -n 2
        --durations=20

pytest.ini文件存储 pytest 设置的配置。因此,您无需提供大量命令行选项,只需键入即可pytest获取所有属性(测试覆盖率、linting 等)。

如果删除该-n 2行,测试仍将运行。希望这能有所帮助。

相关内容