First time here? Check out the FAQ!
-1

Using the testing tool to run Django tests

I have several django tests files . Each one of them has a launch configuration. when I debug individually each test file using the green arrow everything is fine. When I try to use the testing tool, the tests display with a blue question mark. When I right-click run test on one of the files , it displays a line manage.py , the line below is could not read any output from test runner . Then it displays a traceback with an error moduleNotFoundError no module named settings. There seems to be a problem

piscvau's avatar
526
piscvau
asked 2023-12-08 09:06:03 -0600
Wingware Support's avatar
4.2k
Wingware Support
updated 2023-12-08 09:50:04 -0600
edit flag offensive 0 remove flag close merge delete

Comments

add a comment see more comments

6 Answers

1

*FINAL ANSWER*

In the testing tool , django tests should not be manually inserted but found automatically by running all tests from the manage.py file. Each application needs to be a package that is include an __init__.py file tests manuall y inserted into the testing tool will be ran with the unittest environement, not the django tests Thanks to wingware support for helping.

piscvau's avatar
526
piscvau
answered 2024-01-23 02:47:45 -0600
edit flag offensive 0 remove flag delete link

Comments

Correction: Test files that are manually inserted into the testing tool after creating a project as a Django project will also be run with the Django test runner by default, but you can change Default Test Framework under the Testing tab of Project Properties to unittest to get them to run instead with unittest. In that case, manage.py should still be run with the Django test runner because in its File Properties (accessed by right-clicking on manage.py in the Testing tool) it has Test Framework under the Testing tab set to Django Tests and not Default (this is something that New Project also sets up automatically).

Wingware Support's avatar Wingware Support (2024-01-23 08:00:51 -0600) edit
add a comment see more comments
0

I am trying again to use the testing tool for my django project and I do not understand your suggestion of having several manage.py files. Do I have to add a manage.py file with a launch configuration for each test file?

piscvau's avatar
526
piscvau
answered 2024-01-14 12:45:27 -0600
edit flag offensive 0 remove flag delete link

Comments

Yes, if you plan to run your tests using the Django test runner then you need to create a separate file for each launch configuration, add that file to the Testing tool and configure the launch configuration for that file in its File Properties under the Testing tab. Then clicking on one or the other will run tests with each launch configuration. The files can presumably just import the main manage with 'image manage' and then have the usual 'if __name__ == "file": main()' section.

Wingware Support's avatar Wingware Support (2024-01-15 07:47:17 -0600) edit

Hello I am sorry but I do not understand you last suggestion. Should I write import manage in the main section of the file. ?

piscvau's avatar piscvau (2024-01-16 11:41:55 -0600) edit

Yes. I think the files would just contain:

import manage
if __name__ == '__main__':
  manage.main()
Wingware Support's avatar Wingware Support (2024-01-16 16:26:08 -0600) edit

Hello I am sorry but this does not seem to work. when running python manage.py runserver in the terminal window, the project has no problem.

I run a file test which does not use django test but contain an import models.; I copied into the test file the code from above. This does not seem to be efficient because if I put a break point there it never stops. I copied into the launch configuration environment tab :

  • as run arguments : test followed by the name of the file in dotted form
  • the lines which are in the project properties (DJANGO_SITENAME= ....). I run the tests from the green arrow. The tests are launched OK. If I run them from the testing tool. I get an error message saying app registry is not ready. If I delete the run arguments from the launch configuration, when I launch the test ...
(more)
piscvau's avatar piscvau (2024-01-18 08:40:59 -0600) edit

I thought you wanted to run your tests with theDjango test runner and not unittest?! That is what I'm trying to solve at this point, in any case. If that is what you are trying to do then you would put the snippet in my comment above into a file named say env2_manage.py so you can add that file to the Testing tool in Wing in addition to adding manage.py. That then needs to be run by the Django test runner and not as by unittest. The point being that you can set a different Launch Configuration to use under the Testing tab of the File Properties for env2_manage.py.

The file env2_manage.py or whatever you want to call it would be in the same directory as manage.py and you would open it and select Add Current File from the Testing menu in Wing. If you have set Default Test Framework ... (more)

Wingware Support's avatar Wingware Support (2024-01-18 12:56:58 -0600) edit
add a comment see more comments
0

Hello You are right. I did not uncheck the django test framework in the project testing tab properties. If I do uncheck this I can run the unittest test files from the TestingTool . However logically my test files which require django test do not pass. What I need is a way to be able to run all tests with one right click run all tests as well as a right click to run every test file individually.

I conclude that I would be better off in making my project a non django project and adding manage.py and the environment variables to every launch configuration for a test file using django test environment. Is this understanding correct or is there any other way? Will I loose anything regarding template debugging if my project is a non django project? I thank you in advance for your help.

piscvau's avatar
526
piscvau
answered 2024-01-14 12:10:38 -0600
edit flag offensive 0 remove flag delete link

Comments

Which test framework you tell Wing to use doesn't have any effect on other parts of the project configuration, e.g. debugging Django templates. If tests don't work when invoked by unittest it's because the setup magic done by manage.py hasn't been done. I think there is a way to do that manually in your test's setUp() call but I don't know Django well enough to tell you how that's done. I do know you need to make sure DJANGO_SETTINGS_MODULE is defined, but presumably that already is in your Project Properties. You can probably search around using the specific error string you are getting or ask in a Django-specific forum about how to run your tests using unittest and not manage.py.

Wingware Support's avatar Wingware Support (2024-01-15 07:52:46 -0600) edit
add a comment see more comments
0

Some test files are using django test framework, some testfiles are using unittest framework. The first ones have a launch configuration including parameters in the environment tab such as test ,.... Those parameters are the ones which follow manage.py when I run the tests outside of wing. This The second ones are using some environment variable in the environment tab. As mentioned in my question everything is fine when I use either the green arrow or the debug file menu entrance. But it does not work in the testing tool. As for removing the manage.py from the list of files in testing tools; I did remove it but it reappears everytime I launch a test from the testing tool using right click!...Wing systematically add the manage.py. I repeat my request, could you tell me what I should do to make my project a non django project and manually create a manage.py runserver launch configuration.

piscvau's avatar
526
piscvau
answered 2023-12-19 04:27:27 -0600
edit flag offensive 0 remove flag delete link

Comments

After New Project, nothing is set to make the project inherently a "Django project" other than the configuration set up by New Project, which is all visible in Project Properties and in the File Properties of manage.py. I think you have not reset the Default Test Framework under the Testing tab of Project Properties to Unittest as I asked you to in my comment above from Dec 16th. As a result, it is still running manage.py to run your tests and not unittest, and thus the results are shown under manage.py. I'm able to replicate that here if I don't make that configuration change and it does work if I do change the Default Test Framework to Unittest. If you then need to also run tests via manage.py, add it again to the Testing tool, right click on it and check that Test Framework under the Testing Tab of its ... (more)

Wingware Support's avatar Wingware Support (2023-12-19 09:54:25 -0600) edit

Hello Please excuse me. Yes I had not changed the Default Test Framework in the project properties as your comment suggested that I did not use Django Test Framework. Yes I do use it but it is specified in the launch configuration of each file. After resetting the default testFramework, I got rid of the manage.py problem. However I do run into another problemfor which I will open another question. Thanks for your help

piscvau's avatar piscvau (2023-12-20 05:11:50 -0600) edit

Glad that helped!

Wingware Support's avatar Wingware Support (2023-12-20 10:59:25 -0600) edit
add a comment see more comments
0

Hello I am completely lost with the comments above. If I go back to my initial request it is to launch each testfile in the testing tool with a right click. Each test file has a test launch configuration attached to it (in the testing tab). This does not work as described in my first post. I understand your first answer says that this is normal because the named entry point for a Django project is managed.py. Then my request would be to not define my project as a Django project. And I do not know how to do this.

I do not understand the comments you added because I have no need to test manage.py.

piscvau's avatar
526
piscvau
answered 2023-12-16 11:52:32 -0600
edit flag offensive 0 remove flag delete link

Comments

It sounds like you are not actually using the Django testing framework then, but I am not sure. If you run tests outside of Wing are you just running them using unittest, the testing framework that comes with Python's standard library? Or pytest or other testing framework? If so, all you need to do is remove manage.py from the Testing tool and set the Default Testing Framework under the Testing tab in Project Properties to Unittest or whatever testing framework you are using. Then add your testing files to Wing's Testing tool, which you can do either by adding them individually or setting the Test File Patterns under the Testing tab in Project Properties. An example test file pattern is test/test_*.py but of course what you want depends on what your files are called and where they are located. Once that is done, the Environment set under the Testing tab ... (more)

Wingware Support's avatar Wingware Support (2023-12-16 20:39:15 -0600) edit
add a comment see more comments
0

With Django tests (using the Django testing framework) you have to run the whole manage.py file in the Testing tool to get an enumeration of tests there, and then can re-run those individually from the Testing tool view. I don't think right-clicking on the code of individual tests in the editor works because the test file isn't the main entry point in this case. The launch configuration on individual tests is also not used if manage.py is the main entry point for the tests. You would need to set/reset the Testing tab launch configuration on manage.py itself, in its File Properties. This is unfortunate but Django was really not designed with IDEs in mind and this is one area (among a few others) where we have not added Django-specific functionality to compensate for that.

Wingware Support's avatar
4.2k
Wingware Support
answered 2023-12-08 09:49:53 -0600
edit flag offensive 0 remove flag delete link

Comments

Hello I do not understand the workaround you propose. You say I would need to set/reset the testing tab launch configuration on manage.py itself, in its file properties. Since each file has a specific launch configuration , I understand it would mean changing the manage.py file properties each time I need to run a test. Is this understanding is correct, it really drives to the testing tool being unusable as its main purpose is to be able to launch all tests in one click for non regression. It would be easier to give up the django project automatic configuration and manually set up a launch configuration for runserver, makemigrations etc... Could you document this other work around?

piscvau's avatar piscvau (2023-12-09 03:30:22 -0600) edit

Wing expects to have just the one launch env per test file listed in the Testing tool so yes resetting the launch configuration on manage.py is not ideal, unless you do it only rarely. What might work better is to add multiple files to the Teseting tool that are either identical to or similar to manage.py and then you can set the right launch env in the Testing tab for each of those. Then no resetting of things in File Properties is necessary going forward.

Wingware Support's avatar Wingware Support (2023-12-11 09:20:01 -0600) edit

I also saw in a test project I have here that in manage.py there can be something like "os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'dj2.othersettings')" at the top to select a different settings module, which maybe is another way to address this if you do have multiple manage_*.py's for testing.

Wingware Support's avatar Wingware Support (2023-12-11 09:21:16 -0600) edit

And in case it's useful to you or someone else that reads this in the future: If you add other test files to the Testing tool, other than manage.py, those don't necessarily also have to use the Django testing framework. You can set the Test Framework to use to unittest or one of the others in the file's File Properties, under the Testing tab.

Wingware Support's avatar Wingware Support (2023-12-11 09:23:34 -0600) edit
add a comment see more comments

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss.

Add Answer