PyTest not discovering new test module, but changes made in old test modules are reflected in execution
(This has been fixed, please read the edit at the bottom even if nobody submits an answer)
I am writing tests for an app using PyTest, and had three test modules as of this evening. They work as expected, and any changes I make to them are reflected in the test execution (I intentionally put incorrect assertions to be completely sure). However, I added a new module this evening (which also begins with test_ and does not contain a class (so this SO answer does not apply), it is in fact almost identical in structure to one other test module) and no matter what I do PyTest refuses to discover it. I am using VS Code for development, but I tried running pytest from the terminal as well, to the same effect.
This issue on GitHub suggested I try rm -rf .cache
which solved nothing. I tried removing all my __pycache__
files just to be safe as well as the .pytest_cache
file, to no avail. I checked the contents of the .pytest_cache
file after removing and running pytest
again, and none of the new tests are shown in the nodeids
. I do not get any errors, in particular test_grader.py
, test_misc.py
and test_solution_optimal.py
work perfectly fine. Here is proof haha. test_solution_student.py
is an exact copy of test_solution_optimal.py
with a few deliberately incorrect assertions, but pytest won't discover it no matter what I do. Additionally, the __pycache__
in the tests
directory contains a .pyc file corresponding to test_solution_student.py
, which is just plain strange to me. I even tried renaming the file to something different thinking the discovery might be ignoring the second test because they both start with test_solution_
, but nope.
I only enabled pytest as recommended here and the autoTestDiscover.... is enabled as well. However since running pytest from the terminal does not result in the discovery of the last module either I doubt it's an issue with my VS code settings file.
Directory structure:
Top-Level Directory
├── .pytest_cache
│ └── v
├── Grader
│ ├── (Several files to be tested)
│ ├── __init__.py
│ └── __pycache__
├── __pycache__
│ └── globals_store.cpython-37.pyc
├── graphs
│ ├── (Additional irrelevant files)
├── tests
│ ├── __pycache__
│ ├── test_grader.py
│ ├── test_misc.py
│ ├── test_solution_optimal.py
│ └── test_solution_student.py
└── venv
├── bin
├── include
├── lib
└── share
I run pytest
from the Top-Level Directory.
If somebody could give me a lead on what else I could try that might result in the test module being discovered I would forever be in your debt. I am not supposed to share the project since this is part of a homework assignment I am creating, but I am working on reproducing this issue in a dummy project.
Edit:
I "fixed" it; the issue lay with me duplicating the test_solution_optimal
file, (duplicating code did smell funny to me, should have known to trust my intuition but I couldn't use that code out of the box and needed to make subtle modifications) which resulted in me redefining a fixture which I have now moved to a conftest.py
file (I'm new to pytest, please forgive). I now know not to duplicate code (like, ever) but I am still curious as to why this was causing an issue which is why I chose not to add this as an answer to my question. If somebody could chime in with an explanation, be my guest :D
python python-3.x testing pytest
|
show 2 more comments
(This has been fixed, please read the edit at the bottom even if nobody submits an answer)
I am writing tests for an app using PyTest, and had three test modules as of this evening. They work as expected, and any changes I make to them are reflected in the test execution (I intentionally put incorrect assertions to be completely sure). However, I added a new module this evening (which also begins with test_ and does not contain a class (so this SO answer does not apply), it is in fact almost identical in structure to one other test module) and no matter what I do PyTest refuses to discover it. I am using VS Code for development, but I tried running pytest from the terminal as well, to the same effect.
This issue on GitHub suggested I try rm -rf .cache
which solved nothing. I tried removing all my __pycache__
files just to be safe as well as the .pytest_cache
file, to no avail. I checked the contents of the .pytest_cache
file after removing and running pytest
again, and none of the new tests are shown in the nodeids
. I do not get any errors, in particular test_grader.py
, test_misc.py
and test_solution_optimal.py
work perfectly fine. Here is proof haha. test_solution_student.py
is an exact copy of test_solution_optimal.py
with a few deliberately incorrect assertions, but pytest won't discover it no matter what I do. Additionally, the __pycache__
in the tests
directory contains a .pyc file corresponding to test_solution_student.py
, which is just plain strange to me. I even tried renaming the file to something different thinking the discovery might be ignoring the second test because they both start with test_solution_
, but nope.
I only enabled pytest as recommended here and the autoTestDiscover.... is enabled as well. However since running pytest from the terminal does not result in the discovery of the last module either I doubt it's an issue with my VS code settings file.
Directory structure:
Top-Level Directory
├── .pytest_cache
│ └── v
├── Grader
│ ├── (Several files to be tested)
│ ├── __init__.py
│ └── __pycache__
├── __pycache__
│ └── globals_store.cpython-37.pyc
├── graphs
│ ├── (Additional irrelevant files)
├── tests
│ ├── __pycache__
│ ├── test_grader.py
│ ├── test_misc.py
│ ├── test_solution_optimal.py
│ └── test_solution_student.py
└── venv
├── bin
├── include
├── lib
└── share
I run pytest
from the Top-Level Directory.
If somebody could give me a lead on what else I could try that might result in the test module being discovered I would forever be in your debt. I am not supposed to share the project since this is part of a homework assignment I am creating, but I am working on reproducing this issue in a dummy project.
Edit:
I "fixed" it; the issue lay with me duplicating the test_solution_optimal
file, (duplicating code did smell funny to me, should have known to trust my intuition but I couldn't use that code out of the box and needed to make subtle modifications) which resulted in me redefining a fixture which I have now moved to a conftest.py
file (I'm new to pytest, please forgive). I now know not to duplicate code (like, ever) but I am still curious as to why this was causing an issue which is why I chose not to add this as an answer to my question. If somebody could chime in with an explanation, be my guest :D
python python-3.x testing pytest
Well...I can't reproduce this (tried with a smaller example copying a test file in a virtual environment). Do you have this project anywhere you can share? Or give files/code that actually reproduce this? What version of python and pytest are you running? I assume you tried deleting all the__pycache__
and other cache directories everywhere (not just in the tests directory).
– Matt Messersmith
Jan 2 at 3:32
I am not allowed to share this project since I am creating a homework assignment to be rolled out to students next Fall, but I will try to create another project with the issue and revert! Thanks so much :D
– Sanchit Batra
Jan 2 at 3:35
Python Version: 3.7.0, pytest version: 4.0.2
– Sanchit Batra
Jan 2 at 3:35
And indeed, I deleted all the cache files I could lay my hands on haha
– Sanchit Batra
Jan 2 at 3:36
Just tried with your version of python/pytest, still a no-go. I am on a mac, too. Cannot reproduce, sorry. If you can get a reproducible example that you can share I'd be interested in helping.
– Matt Messersmith
Jan 2 at 3:46
|
show 2 more comments
(This has been fixed, please read the edit at the bottom even if nobody submits an answer)
I am writing tests for an app using PyTest, and had three test modules as of this evening. They work as expected, and any changes I make to them are reflected in the test execution (I intentionally put incorrect assertions to be completely sure). However, I added a new module this evening (which also begins with test_ and does not contain a class (so this SO answer does not apply), it is in fact almost identical in structure to one other test module) and no matter what I do PyTest refuses to discover it. I am using VS Code for development, but I tried running pytest from the terminal as well, to the same effect.
This issue on GitHub suggested I try rm -rf .cache
which solved nothing. I tried removing all my __pycache__
files just to be safe as well as the .pytest_cache
file, to no avail. I checked the contents of the .pytest_cache
file after removing and running pytest
again, and none of the new tests are shown in the nodeids
. I do not get any errors, in particular test_grader.py
, test_misc.py
and test_solution_optimal.py
work perfectly fine. Here is proof haha. test_solution_student.py
is an exact copy of test_solution_optimal.py
with a few deliberately incorrect assertions, but pytest won't discover it no matter what I do. Additionally, the __pycache__
in the tests
directory contains a .pyc file corresponding to test_solution_student.py
, which is just plain strange to me. I even tried renaming the file to something different thinking the discovery might be ignoring the second test because they both start with test_solution_
, but nope.
I only enabled pytest as recommended here and the autoTestDiscover.... is enabled as well. However since running pytest from the terminal does not result in the discovery of the last module either I doubt it's an issue with my VS code settings file.
Directory structure:
Top-Level Directory
├── .pytest_cache
│ └── v
├── Grader
│ ├── (Several files to be tested)
│ ├── __init__.py
│ └── __pycache__
├── __pycache__
│ └── globals_store.cpython-37.pyc
├── graphs
│ ├── (Additional irrelevant files)
├── tests
│ ├── __pycache__
│ ├── test_grader.py
│ ├── test_misc.py
│ ├── test_solution_optimal.py
│ └── test_solution_student.py
└── venv
├── bin
├── include
├── lib
└── share
I run pytest
from the Top-Level Directory.
If somebody could give me a lead on what else I could try that might result in the test module being discovered I would forever be in your debt. I am not supposed to share the project since this is part of a homework assignment I am creating, but I am working on reproducing this issue in a dummy project.
Edit:
I "fixed" it; the issue lay with me duplicating the test_solution_optimal
file, (duplicating code did smell funny to me, should have known to trust my intuition but I couldn't use that code out of the box and needed to make subtle modifications) which resulted in me redefining a fixture which I have now moved to a conftest.py
file (I'm new to pytest, please forgive). I now know not to duplicate code (like, ever) but I am still curious as to why this was causing an issue which is why I chose not to add this as an answer to my question. If somebody could chime in with an explanation, be my guest :D
python python-3.x testing pytest
(This has been fixed, please read the edit at the bottom even if nobody submits an answer)
I am writing tests for an app using PyTest, and had three test modules as of this evening. They work as expected, and any changes I make to them are reflected in the test execution (I intentionally put incorrect assertions to be completely sure). However, I added a new module this evening (which also begins with test_ and does not contain a class (so this SO answer does not apply), it is in fact almost identical in structure to one other test module) and no matter what I do PyTest refuses to discover it. I am using VS Code for development, but I tried running pytest from the terminal as well, to the same effect.
This issue on GitHub suggested I try rm -rf .cache
which solved nothing. I tried removing all my __pycache__
files just to be safe as well as the .pytest_cache
file, to no avail. I checked the contents of the .pytest_cache
file after removing and running pytest
again, and none of the new tests are shown in the nodeids
. I do not get any errors, in particular test_grader.py
, test_misc.py
and test_solution_optimal.py
work perfectly fine. Here is proof haha. test_solution_student.py
is an exact copy of test_solution_optimal.py
with a few deliberately incorrect assertions, but pytest won't discover it no matter what I do. Additionally, the __pycache__
in the tests
directory contains a .pyc file corresponding to test_solution_student.py
, which is just plain strange to me. I even tried renaming the file to something different thinking the discovery might be ignoring the second test because they both start with test_solution_
, but nope.
I only enabled pytest as recommended here and the autoTestDiscover.... is enabled as well. However since running pytest from the terminal does not result in the discovery of the last module either I doubt it's an issue with my VS code settings file.
Directory structure:
Top-Level Directory
├── .pytest_cache
│ └── v
├── Grader
│ ├── (Several files to be tested)
│ ├── __init__.py
│ └── __pycache__
├── __pycache__
│ └── globals_store.cpython-37.pyc
├── graphs
│ ├── (Additional irrelevant files)
├── tests
│ ├── __pycache__
│ ├── test_grader.py
│ ├── test_misc.py
│ ├── test_solution_optimal.py
│ └── test_solution_student.py
└── venv
├── bin
├── include
├── lib
└── share
I run pytest
from the Top-Level Directory.
If somebody could give me a lead on what else I could try that might result in the test module being discovered I would forever be in your debt. I am not supposed to share the project since this is part of a homework assignment I am creating, but I am working on reproducing this issue in a dummy project.
Edit:
I "fixed" it; the issue lay with me duplicating the test_solution_optimal
file, (duplicating code did smell funny to me, should have known to trust my intuition but I couldn't use that code out of the box and needed to make subtle modifications) which resulted in me redefining a fixture which I have now moved to a conftest.py
file (I'm new to pytest, please forgive). I now know not to duplicate code (like, ever) but I am still curious as to why this was causing an issue which is why I chose not to add this as an answer to my question. If somebody could chime in with an explanation, be my guest :D
python python-3.x testing pytest
python python-3.x testing pytest
edited Jan 2 at 5:55
Sanchit Batra
asked Jan 2 at 3:09
Sanchit BatraSanchit Batra
5329
5329
Well...I can't reproduce this (tried with a smaller example copying a test file in a virtual environment). Do you have this project anywhere you can share? Or give files/code that actually reproduce this? What version of python and pytest are you running? I assume you tried deleting all the__pycache__
and other cache directories everywhere (not just in the tests directory).
– Matt Messersmith
Jan 2 at 3:32
I am not allowed to share this project since I am creating a homework assignment to be rolled out to students next Fall, but I will try to create another project with the issue and revert! Thanks so much :D
– Sanchit Batra
Jan 2 at 3:35
Python Version: 3.7.0, pytest version: 4.0.2
– Sanchit Batra
Jan 2 at 3:35
And indeed, I deleted all the cache files I could lay my hands on haha
– Sanchit Batra
Jan 2 at 3:36
Just tried with your version of python/pytest, still a no-go. I am on a mac, too. Cannot reproduce, sorry. If you can get a reproducible example that you can share I'd be interested in helping.
– Matt Messersmith
Jan 2 at 3:46
|
show 2 more comments
Well...I can't reproduce this (tried with a smaller example copying a test file in a virtual environment). Do you have this project anywhere you can share? Or give files/code that actually reproduce this? What version of python and pytest are you running? I assume you tried deleting all the__pycache__
and other cache directories everywhere (not just in the tests directory).
– Matt Messersmith
Jan 2 at 3:32
I am not allowed to share this project since I am creating a homework assignment to be rolled out to students next Fall, but I will try to create another project with the issue and revert! Thanks so much :D
– Sanchit Batra
Jan 2 at 3:35
Python Version: 3.7.0, pytest version: 4.0.2
– Sanchit Batra
Jan 2 at 3:35
And indeed, I deleted all the cache files I could lay my hands on haha
– Sanchit Batra
Jan 2 at 3:36
Just tried with your version of python/pytest, still a no-go. I am on a mac, too. Cannot reproduce, sorry. If you can get a reproducible example that you can share I'd be interested in helping.
– Matt Messersmith
Jan 2 at 3:46
Well...I can't reproduce this (tried with a smaller example copying a test file in a virtual environment). Do you have this project anywhere you can share? Or give files/code that actually reproduce this? What version of python and pytest are you running? I assume you tried deleting all the
__pycache__
and other cache directories everywhere (not just in the tests directory).– Matt Messersmith
Jan 2 at 3:32
Well...I can't reproduce this (tried with a smaller example copying a test file in a virtual environment). Do you have this project anywhere you can share? Or give files/code that actually reproduce this? What version of python and pytest are you running? I assume you tried deleting all the
__pycache__
and other cache directories everywhere (not just in the tests directory).– Matt Messersmith
Jan 2 at 3:32
I am not allowed to share this project since I am creating a homework assignment to be rolled out to students next Fall, but I will try to create another project with the issue and revert! Thanks so much :D
– Sanchit Batra
Jan 2 at 3:35
I am not allowed to share this project since I am creating a homework assignment to be rolled out to students next Fall, but I will try to create another project with the issue and revert! Thanks so much :D
– Sanchit Batra
Jan 2 at 3:35
Python Version: 3.7.0, pytest version: 4.0.2
– Sanchit Batra
Jan 2 at 3:35
Python Version: 3.7.0, pytest version: 4.0.2
– Sanchit Batra
Jan 2 at 3:35
And indeed, I deleted all the cache files I could lay my hands on haha
– Sanchit Batra
Jan 2 at 3:36
And indeed, I deleted all the cache files I could lay my hands on haha
– Sanchit Batra
Jan 2 at 3:36
Just tried with your version of python/pytest, still a no-go. I am on a mac, too. Cannot reproduce, sorry. If you can get a reproducible example that you can share I'd be interested in helping.
– Matt Messersmith
Jan 2 at 3:46
Just tried with your version of python/pytest, still a no-go. I am on a mac, too. Cannot reproduce, sorry. If you can get a reproducible example that you can share I'd be interested in helping.
– Matt Messersmith
Jan 2 at 3:46
|
show 2 more comments
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54000802%2fpytest-not-discovering-new-test-module-but-changes-made-in-old-test-modules-are%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54000802%2fpytest-not-discovering-new-test-module-but-changes-made-in-old-test-modules-are%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Well...I can't reproduce this (tried with a smaller example copying a test file in a virtual environment). Do you have this project anywhere you can share? Or give files/code that actually reproduce this? What version of python and pytest are you running? I assume you tried deleting all the
__pycache__
and other cache directories everywhere (not just in the tests directory).– Matt Messersmith
Jan 2 at 3:32
I am not allowed to share this project since I am creating a homework assignment to be rolled out to students next Fall, but I will try to create another project with the issue and revert! Thanks so much :D
– Sanchit Batra
Jan 2 at 3:35
Python Version: 3.7.0, pytest version: 4.0.2
– Sanchit Batra
Jan 2 at 3:35
And indeed, I deleted all the cache files I could lay my hands on haha
– Sanchit Batra
Jan 2 at 3:36
Just tried with your version of python/pytest, still a no-go. I am on a mac, too. Cannot reproduce, sorry. If you can get a reproducible example that you can share I'd be interested in helping.
– Matt Messersmith
Jan 2 at 3:46