Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

217
Views
Run unit tests without generating assets when using django-webpack-loader

I'm working on a Django project with some amount of front-end JavaScript code. I'm in the process of migrating the JavaScript packaging and minification from djanog-pipeline to webpack with django-webpack-loader.

django-webpack-loader works by running webpack separate from any Django processes to generate packed bundles. django-webpack-loader will then read a JSON file written by webpack-bundle-tracker and use the information to insert the correct paths into HTML templates.

This works flawlessly but there is one catch: Some of our unit tests will access the Django application using the integrated Django test client, which renders full HTML responses so that tests can inspect the generated result. Test may be run without any webpack-related setup having been done. So the packed bundles and JSON file may not exist. These are not necessary for the purpose of testing the frontend code, only the dynamically generated HTML is inspected. Having test fail just because someone forgot to run webpack leads to frustration.

Ideally, I would have django-webpack-loader just use dummy URLs in the inserted <script> tags while running tests, removing the dependency on files generated by webpack. What options do I have to resolve this dependency?

about 4 years ago · Santiago Trujillo
2 answers
Answer question

0

And if you want to do it at a higher level for all tests ran by pytest, you can add to your conftest.py:

@fixture(autouse=True)
def no_webpack_loaded(monkeypatch):
    def mockreturn(loader, bundle_name):
        return []
    monkeypatch.setattr(WebpackLoader, "get_bundle", mockreturn)
about 4 years ago · Santiago Trujillo Report

0

You can patch the loader altogether to bypass anything that django-webpack-loader might do:

from mock import patch

...

@patch('webpack_loader.loader.WebpackLoader.get_bundle')
def test(self, mock_wpl, client):
    mock_wpl.return_value = []
    response = client.get("/")
    assert response.status_code == 200
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!