Open SanketDG opened 8 years ago
Could you describe your problem in more details please? It's not clear to me what you mean by "I have a codebase where I need to test the contents of python files. Unfortunately, this test files are syntactically invalid, and they are being collected which causes them to fail."
Um, so I have python files like these:
def empty():
"""
this is heavy
:param x:
:return:"""return 88
As you can see, this is invalid python and would return a compilation error if compiled.
I have "test files" like this i.e. files I just read... I dont want them to be collected. Is that clear?
Thanks!
How are you naming these test files? You can control which files pytest tries to collect as test files using the python_files
configuration variable. Docs: http://doc.pytest.org/en/latest/customize.html?highlight=python_files#confval-python_files
Um they are in bad_file*.py
format.
You can control which files pytest tries to collect as test files using the python_files configuration variable.
This is what I am more confused about. In my setup.cfg:
[pytest]
norecursedirs =
.git
dist
build
venv
.env
python_files = *Test.py
python_classes = *Test
python_functions = *_test
timeout = 35
addopts = --color=yes --ignore=test-requirements.txt
env =
PYTHONHASHSEED=0
# PYTHONHASHSEED=0 is required to use same hashes in pytests-xdist's workers
[coverage:run]
branch = True
cover_pylib = False
source =
.
omit =
tests/*
.ci/*
setup.py
[coverage:report]
show_missing = True
So python_files
shouldn't pick that up.
Here are the two errors:
_______________________ ERROR collecting tests/documentation/test_files/DocumentationStyleBear/bad_file2.py ________________________
../.virtualenvs/coala/lib/python3.4/site-packages/py/_path/local.py:650: in pyimport
__import__(modname)
E File "/home/sanket/coala-bears/tests/documentation/test_files/DocumentationStyleBear/bad_file2.py", line 1
E def x:
E ^
E SyntaxError: invalid syntax
_______________________ ERROR collecting tests/documentation/test_files/DocumentationStyleBear/bad_file3.py ________________________
../.virtualenvs/coala/lib/python3.4/site-packages/py/_path/local.py:650: in pyimport
__import__(modname)
E File "/home/sanket/coala-bears/tests/documentation/test_files/DocumentationStyleBear/bad_file3.py", line 6
E """
E this is heavy
E
E :param x:
E :return:"""return 88
E
E
E
E
E ^
E SyntaxError: invalid syntax
Hmm that's strange, can you post a reproducible example?
Sure
$ git clone git@github.com:coala-analyzer/coala-bears.git
$ git checkout sanketdg/docformatbear
$ pip install -r test-requirements.txt
$ py.test
That branch doesn't seem to exist in your repo.
@The-Compiler sorry, I have updated the same.
I can't reproduce this. tests/documentation/DocumentationStyleBearTest.py
is the only thing collected in tests/documentation
here.
Could you maybe share a full terminal session where you reproduce this, ideally from zero and with a clean virtualenv?
Interesting, looks like a git clean -dfx
worked, and it doesn't seem to collect it anymore.
Hmm still it's a little strange.
Anyway, can we close this now?
Sure, but after pushing the CI still fails. https://circleci.com/gh/coala-analyzer/coala-bears/2863
I can reproduce this by doing pytest --doctest-modules tests
. Can you actually reproduce it without --doctest-modules
like you said above?
@The-Compiler, yep this is it! It doesn't work with --doctest-modules
!
Okay - I'll let someone else take a look then, as I have no idea about pytest's doctest integration.
By the way: To make things easier, in the future please try actually reproducing your issue with the given reproduction steps - an example which doesn't actually reproduce the problem is quite useless and only makes people spend time on trying to see why they can't reproduce it instead of fixing the bug :wink:
Thanks for submitting an issue!
Here's a quick checklist in what to include:
I have a codebase where I need to test the contents of python files. Unfortunately, this test files are syntactically invalid, and they are being collected which causes them to fail. I do not want to collect them since they are test files.
pip list
of the virtual environment you are using